Opened 15 years ago
Closed 11 years ago
#11521 closed Bug (fixed)
QuerySet.update() doesn't accept fkey assignment by id (with patch)
Reported by: | Jerome Leclanche | Owned by: | Jerome Leclanche |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | adys.wh@…, timograham@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
QuerySet.update doesn't accept FIELD_id assignments for ForeignKeys. This prevents the user from using the same dict to create or update a key.
Attached patch solves that problem by adding attname keys in the field cache. It may or may not be a hack.
Attachments (1)
Change History (11)
by , 15 years ago
Attachment: | fkeyassignbyid.patch added |
---|
comment:1 by , 15 years ago
Owner: | changed from | to
---|
comment:3 by , 15 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:7 by , 12 years ago
Cc: | added |
---|---|
Needs tests: | unset |
Added a test:
https://github.com/django/django/pull/1246
comment:8 by , 12 years ago
As discussed in the pull request the change done to Options.init_name_map will effectively turn the allow_explicit_fk parameter useless. The change done is adding field.attname to the name map. The allow_explicit_fk parameter is used in join generation inside the sql/query.py, and it allows using attname for lookups when the parameter is set. The parameter is set for filter() and values() calls at least, but isn't set for some other operations, like annotate(). I can't see any reason for the inconsistency - either allow attname everywhere or nowhere.
One test fails if the change to init_name_map and removal of allow_explicit_fk is done. The failing test is lookup.tests.LookupTests.test_error_messages, it fails because author_id is in the error message's "allowed choices" list in addition to author. But, that is actually correct, author_id is an allowed choice.
Any opposition for making this change at alpha stage? There is a minor risk this could break something.
The proposed change will also fix this ticket's issue. A patch is available from: https://github.com/akaariai/django/compare/ticket_11521
comment:9 by , 11 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
We can make this change for 1.7. Patch still applies cleanly and tests pass.
comment:10 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Add attname to field cache