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

Make re_path -> path fixer convert include()s with unterminated regexes #263

Closed
amrishparmar opened this issue Oct 5, 2022 · 3 comments · Fixed by #279
Closed

Make re_path -> path fixer convert include()s with unterminated regexes #263

amrishparmar opened this issue Oct 5, 2022 · 3 comments · Fixed by #279

Comments

@amrishparmar
Copy link

Python Version

3.10.7

Django Version

4.1.2

Package Version

1.10.0

Description

Not sure if this is a bug strictly speaking or a feature request, but after running this package with --target-version 4.1 the fixer that converts re_path usage to path misses cases which should result in a direct translation.

An example from our codebase is
re_path(r"^accounts/", include("allauth.urls")),

In the current version this line is left unmodified.

Presumably something like this could be automatically converted to
path("accounts/", include("allauth.urls")),

@adamchainz
Copy link
Owner

Ah right, currently the fixer only considers regexes that end with $, which prevents it from applying in this situation. I think we could maybe allow non-$-terminated regexes for include() only. It's not safe to convert for views since the lack of $ means the regex matches any characters at the end.

@UnknownPlatypus
Copy link
Contributor

Agree, it's looking safe for the include() case, should be quite a simple update to support this case.

Should I step in for a patch ? I've seen you started some refactoring to fix #250 so maybe we should wait for this before doing more work on this fixer?

PS: @amrishparmar See #121 for reference on why it's not safe for views.

@adamchainz
Copy link
Owner

Yeah it needs to wait until #250 is fixed. If you want to make an alternate PR before I get to work on it, feel free.

@adamchainz adamchainz changed the title re_path -> path converter missing some cases Make re_path -> path fixer convert include()s with unterminated regexes Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants