#30627: In multi-table inheritance, querying with invalid pk raises different
exception depending on the inheritance level
-------------------------------------+-------------------------------------
               Reporter:  Antonis    |          Owner:  nobody
  Christofides                       |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 **Steps to reproduce**:

 1. Create these models:
 {{{
 class Animal(models.Model):
     pass

 class Mammal(Animal):
     pass

 class Cat(Mammal):
     pass
 }}}

 2. Query by pk, using a string instead of an integer:
 {{{
 Animal.objects.get(pk="hello")
 Mammal.objects.get(pk="hello")
 Cat.objects.get(pk="hello")
 }}}

 **Result**: Querying `Animal` and `Mammal` raises a `ValueError` with the
 message "invalid literal for int() with base 10: 'hello'". This appears to
 be the desired behavior. However, querying `Cat` constructs an SQL query
 and attempts to run it, usually resulting in 'DataError: invalid input
 syntax for integer: "hello"'.

 **Expected result**: In all cases the same exception should have been
 raised.

 A practical problem caused by this is that if you give my app a wrong URL
 like `/api/stations/hello/` (instead of e.g. `/api/stations/25/`), it
 results in an internal server error when it should have returned 404. The
 reason is that django-rest-framework catches `ValueError` but does not
 catch `DataError`.

 I'm also attaching a file that you can merely run and it demonstrates the
 problem.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30627>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.4bb6c6bd43c57e16124ad5277bb7ee93%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to