﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30627	In multi-table inheritance, querying with invalid pk raises different exception depending on the inheritance level.	Antonis Christofides	nobody	"**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."	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	0	0	0	0	0	0
