Opened 5 years ago

Last modified 5 years ago

#30587 closed New feature

Exceptions thrown by 'get_object_or_404()' shortcut method — at Initial Version

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

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:

  1. Below statement raises valueError:

    get_object_or_404(Test1, pk='test')

    • invalid literal for int() with base 10: 'test'
  1. Below statement raises ValidationError:

    get_object_or_404(Test2, pk="test")

    • 'test' is not a valid UUID.

So this method will throw diffrent exceptions in diffenrent scenario. So would it be possible to raise 404 exceptions even if it finds invalid values.

Change History (0)

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