Opened 17 years ago
Closed 16 years ago
#7136 closed (fixed)
when inheriting models, accessing related subclass instances can produce spurious relations depending on order
Reported by: | Andy MacKinlay | Owned by: | socrates |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | model inheritance | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you are using the new multi-table inheritance feature, and have two or more subclasses (eg SubClassA and SubClassB) which inherits from a baseclass, and retrieve a base class instance baseinstance
from the DB, the expected behaviour if baseinstance
only has a corresponding SubClassA instance should be to throw a DoesNotExist exception when accessing baseinstance.subclassb
. However, if you have already accessed baseinstance.subclassa
, baseinstance.subclassb
will point to the corresponding SubClassA instance instead of raising the exception.
The attached models.py includes a test case that documents this.
Attachments (5)
Change History (12)
by , 17 years ago
comment:1 by , 17 years ago
Owner: | changed from | to
---|
comment:2 by , 17 years ago
Status: | new → assigned |
---|
by , 17 years ago
Attachment: | shell_results.py added |
---|
This file is to easily reproduce the shell results and see the situation before and after the patch
comment:3 by , 17 years ago
Has patch: | set |
---|
As it tuns out the bug was even a bit more extensive: not only accessing a non existing subclass goes wrong. Also if the subclass does exist then in some special cases (multiple inheritance) the wrong object is returned (see shell_result.py). The patch (patch_for_rev7513.diff) contains a doctest that describes multiple model inheritance.
comment:4 by , 17 years ago
The patch fixes the problem but I am not certain if this is the right way to go about it. The problem was initially caused because of name collisions in the SingleRelatedObjectDescriptor.cache_name. Maybe a different naming contvention for the cache_name is the right way to fix it.
by , 17 years ago
Attachment: | patch_for_rev7513_alternative.diff added |
---|
an alternative pach. in stead of stricter type checking it avoids name collisions by changing the cache_name.
by , 17 years ago
Attachment: | shell_results_rev7513.py added |
---|
This file is to easily reproduce the shell results and see the situation before and after the patch (this version includes the models)
comment:5 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
I'm marking this as accepted, here's another test I put together that shows the problem: http://dpaste.com/hold/48236/
comment:6 by , 16 years ago
It seems that this bug has already been fixed somewhere else so this ticket can be closed as duplicate.
comment:7 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
This was indeed fixed(don't have the revision handy).
model file with included doctest to replicate the issue