Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django URL patterns broken in 1.32.0 #2446

Closed
nijel opened this issue Oct 15, 2023 · 6 comments · Fixed by #2452
Closed

Django URL patterns broken in 1.32.0 #2446

nijel opened this issue Oct 15, 2023 · 6 comments · Fixed by #2452
Assignees

Comments

@nijel
Copy link
Contributor

nijel commented Oct 15, 2023

How do you use Sentry?

Self-hosted/on-premise

Version

1.32.0

Steps to Reproduce

  1. Upgrade to 1.32.0
  2. Access URL with "translate/<object_path:path>/" path

The urls.py:

https://github.com/WeblateOrg/weblate/blob/03fb51dadc115828b745ca4255be1d5ae0451349/weblate/urls.py#L117-L121

Pattern definition:

https://github.com/WeblateOrg/weblate/blob/03fb51dadc115828b745ca4255be1d5ae0451349/weblate/utils/urls.py#L29-L36

Most likely this is caused by #2432

Expected Result

The event would be captured as /translate/{path}/ as it was before.

Actual Result

Instead, it is captured as /projects/{path}{0,6})/ what is IMHO wrong as there is no repetition of the path argument, the repetition is embedded in it (also, there is extra closing parenthesis).

@sentrivana
Copy link
Contributor

Hey @nijel, thanks for raising this. This is indeed caused by the linked PR reverting the change that caused this regression. (I elaborated on the underlying issue in this comment.) In your case, it's the closing parenthesis in the regex that's throwing our resolver off. (Which shouldn't happen and is a bug.)

We can't revert to the behavior in 1.31.0 since it breaks multiple groups. Fixing this will require more fundamental changes to the resolver -- as I wrote in the linked comment, what we're currently doing is by design a best effort solution. We have to investigate how to do this properly and it'll likely take some time.

@sentrivana
Copy link
Contributor

Related: #1527

@sentrivana sentrivana added this to the Django update milestone Oct 16, 2023
@nijel
Copy link
Contributor Author

nijel commented Oct 16, 2023

Maybe I'm missing something, but why not use ResolverMatch? It is available as request.resolver_match after resolving and has route attribute which contains the actual pattern that matched (translate/<object_path:path>/ in the above case). Processing such string seems much easier than dealing with regex...

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Oct 16, 2023
@sentrivana
Copy link
Contributor

ResolverMatch could definitely work and would probably be the cleanest way to go about this. I'll look into it.

@sl0thentr0py
Copy link
Member

@sentrivana yes please, if we can just use the django stuff directly, let's do that.
This LEGACY_RESOLVER is ported all the way from raven long ago. I just think no one looked at it later.

@sentrivana
Copy link
Contributor

So ResolverMatch didn't prove to be the shiny solution I'd hoped it would be -- we already have access to the original URL pattern in the RavenResolver, so no need for getting it via ResolverMatch. That being said, I did what was suggested here, which is parsing the path directly without turning it into its regex counterpart first, which was the source of the issue here. Added some tests and also tested manually with the custom PathConverter from this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants