Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#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 Fraterius)

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 Fraterius, 5 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 5 years ago

Resolution: wontfix
Status: newclosed
Type: UncategorizedCleanup/optimization
Version: 2.2master

Thanks for the report, however this is documented, tested, and expected behavior.

The assumption is that to_python() in custom converters will raise ValueError if it cannot convert the given value which means no match and 404 as a consequence.

in reply to:  2 comment:3 by Fraterius, 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 raise ValueError if it cannot convert the given value which means no match and 404 as a consequence.

comment:4 by Mariusz Felisiak, 5 years ago

Component: Core (URLs)Documentation
Easy pickings: set
Resolution: wontfix
Status: closednew
Summary: Django is silence on ValueError in converter to_python() method.Clarifiy that ValueError raised by converter.to_python() causes 404.
Triage Stage: UnreviewedAccepted

We can add short clarification.

comment:5 by Mariusz Felisiak, 5 years ago

@Fraterius Patches welcome!

comment:6 by Fraterius, 5 years ago

@felixxm I'll prepare something next week.

comment:7 by Mariusz Felisiak, 5 years ago

Has patch: set
Owner: changed from nobody to Shashank Parekh
Status: newassigned

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In f197c3dd:

Fixed #30600 -- Clarified that ValueError raised by converter.to_python() means no match.

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 0ea952e3:

[2.2.x] Fixed #30600 -- Clarified that ValueError raised by converter.to_python() means no match.

Backport of f197c3dd9130b18397022605c27ffe5755f329d7 from master

Note: See TracTickets for help on using tickets.
Back to Top