#30600 closed Cleanup/optimization (fixed)
Clarifiy that ValueError raised by converter.to_python() causes 404.
Reported by: | Fraterius | Owned by: | Shashank Parekh |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | url pattern converter regexp |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
Yesterday I've been debugging for few hours my regexp in Converter class which seems to be not working correctly, when the real problem was my Converter's to_python() method which doesn't handle ValueError.
Django instead letting me know where lies the problem simply didn't find matching pattern and returned 404 (so it acted like a regexp problem).
The line responsible for that is:
https://github.com/django/django/blob/26d16c07fdc4a297daca554afa6375c70d6d82a9/django/urls/resolvers.py#L256
I think this should be handled in different manner. At least some note in the documentation letting user know that all ValueError's in Converters method are handled silently (which is somehow not intuitive).
Change History (9)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|
follow-up: 3 comment:2 by , 5 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
Version: | 2.2 → master |
comment:3 by , 5 years ago
Like You said great that it should rise ValueError, but there should be the sentence that You wrote, what will happen if it rises ValueError (at least). I guaranty that there will be more such devs like me, as it really is not intuitive. Is it a problem to make it like a note in the docs? 404 as a consequence isn't so obvious for everyone and it's nowhere in the docs.
Replying to felixxm:
Thanks for the report, however this is documented, tested, and expected behavior.
The assumption is that
to_python()
in custom converters will raiseValueError
if it cannot convert the given value which means no match and 404 as a consequence.
comment:4 by , 5 years ago
Component: | Core (URLs) → Documentation |
---|---|
Easy pickings: | set |
Resolution: | wontfix |
Status: | closed → new |
Summary: | Django is silence on ValueError in converter to_python() method. → Clarifiy that ValueError raised by converter.to_python() causes 404. |
Triage Stage: | Unreviewed → Accepted |
We can add short clarification.
Thanks for the report, however this is documented, tested, and expected behavior.
The assumption is that
to_python()
in custom converters will raiseValueError
if it cannot convert the given value which means no match and 404 as a consequence.