Opened 5 years ago
Closed 5 years ago
#30587 closed New feature (duplicate)
Cloaking exceptions raised by get_object_or_404(). — at Version 2
Reported by: | Ishwar Bhat | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When we use get_object_or_404() method to query an object, sometimes due to invalid inputs it will through exceptions. Instead can it raise 404 directly?
Ex:
Models:
>>class Test1(models.Model): >> c2 = models.CharField(max_length=10) >>class Test2(models.Model): >> c1 = models.UUIDField(primary_key=True, default=uuid.uuid4) >> c2 = models.CharField(max_length=10)
query:
- Below statement raises valueError:
>> get_object_or_404(Test1, pk='test') >> - invalid literal for int() with base 10: 'test'
- Below statement raises ValidationError:
>> get_object_or_404(Test2, pk="test") >> - 'test' is not a valid UUID.
So this method will throw different exceptions in different scenario. So would it be possible to raise 404 exceptions even if it finds invalid values.
Change History (2)
comment:1 by , 5 years ago
comment:2 by , 5 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Description: | modified (diff) |
Resolution: | → duplicate |
Status: | new → closed |
Summary: | Exceptions thrown by 'get_object_or_404()' shortcut method → Cloaking exceptions raised by get_object_or_404(). |
Version: | 2.2 → master |
Duplicate of #22303.
Note:
See TracTickets
for help on using tickets.
Yes this behavior exists.
But it seems more appropriate to throw the errors instead of 404.
This seems to be more of a server issue of trying to compare strings with integers rather than an inappropriate client input