#30587: Cloaking exceptions raised by get_object_or_404(). -------------------------------------+------------------------------------- Reporter: Ishwar Bhat | Owner: nobody Type: New feature | Status: closed Component: Database layer | Version: master (models, ORM) | Severity: Normal | Resolution: duplicate Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by felixxm):
* status: new => closed * component: Uncategorized => Database layer (models, ORM) * version: 2.2 => master * resolution: => duplicate Old 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' > > 2. 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. New 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' }}} 2. 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. -- Comment: Duplicate of #22303. -- Ticket URL: <https://code.djangoproject.com/ticket/30587#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.4fdf4724555b3a78c079ca3eeb0a6a75%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.