Opened 16 years ago
Closed 15 years ago
#10785 closed (duplicate)
ForeignKey get_db_prep_lookup doesn't work for custom primary key if full object isn't passed
Reported by: | Alex Gaynor | Owned by: | Malcolm Tredinnick |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | bretthoerner@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
This is a slight variant on #7823. That fixed it so Foo.objects.filter(bar=bar_obj)
works, however Foo.objects.filter(bar_id=bar_obj.pk)
fails(assuming bar has some sort of custom primary key).
Attachments (2)
Change History (15)
comment:1 by , 16 years ago
Cc: | added |
---|
by , 16 years ago
Attachment: | custom_pk.diff added |
---|
comment:2 by , 16 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 16 years ago
Attachment: | custom_pk.2.diff added |
---|
comment:4 by , 16 years ago
Owner: | changed from | to
---|---|
Patch needs improvement: | set |
Status: | new → assigned |
Are you intending to fix the tests?
I'll incorporate fixing the main problem into the work I'm doing for #10243 -- get_db_prep_lookup()
on related fields is broken in a couple of interesting ways right now and needs heavy hammer surgery that I'm in the middle of. But a test case that actually demonstrates the problem is going to save time, so a proper patch against the test suite would be appreciated.
comment:5 by , 16 years ago
I just fixed up those tests, I originally uploaded the first version imperfect because I wanted to get it up and for the gentleman who reported the bug to me to be able to see it easily.
comment:6 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:7 by , 15 years ago
For the record - I've spoken with Malcolm about the underlying problem here, and we've opted to paper over the immediate problem in the interests of getting v1.1 out the door. We will need to revisit get_db_prep_lookup in the 1.2 timeframe.
comment:8 by , 15 years ago
comment:9 by , 15 years ago
comment:10 by , 15 years ago
comment:11 by , 15 years ago
comment:12 by , 15 years ago
milestone: | 1.1 |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
As noted in the previous two commit comments, this change was reverted due to introducing some other problems. Those problems were much more mainstream than this one, so fixing those issues takes priority. The test case has been left in place (mostly because it partly served to test the behavior introduced in #7823), but is commented out for now.
Deeper investigation has revealed that this isn't something we can paper over - the problem is actually quite deep. Note to self: Listen to Malcolm. :-)
Given that this is an edge case, there is a workaround (use the object instead of the PK), and the actual solution will be very complex (and will potentially introduce all sorts of other #11311-esque breakages) I'm going to defer this from the v1.1 milestone.
comment:13 by , 15 years ago
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
Since this is a smaller part of a much bigger problem, I'm going to close this as a duplicate of a new ticket (#11319) that covers the bigger issue.
Patch that solved the problem. 2 problems with it: 1) The tests are in the wrong place, they're there since that's where the issue was originally reported to me. 2) The tests require py2.5 since that's when the UUID module was added