Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#757 closed defect (fixed)

Cannot set primary key value manually for new objects.

Reported by: cygnus@… Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When calling for objects whose primary key values *do not* exist in the model table, an auto-assigned primary key value is used instead of the one that I assign in my program. For example, this code will result in a primary key based on a db.get_last_insert_id call rather than the value I assign (assuming no record with id = 15 exists in the model table):

obj = SomeModel() = 15

The code in meta/ assumes that if the ID does not already exist, an INSERT must take place and any auto-assign fields must get their values accordingly.

Attachments (1)

pk_save.diff (1.6 KB) - added by cygnus@… 13 years ago.
Patch to make saving primary key values work.

Download all attachments as: .zip

Change History (3)

Changed 13 years ago by cygnus@…

Attachment: pk_save.diff added

Patch to make saving primary key values work.

comment:1 Changed 13 years ago by cygnus@…

I've added a small patch to fix this issue, but I cannot attest to whether other issues remain (for example, whether calling f.pre_save() on some AutoField f will never be problematic). I've tested this and it works as expected under the circumstances I described.

comment:2 Changed 13 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [1511]) Fixed #757: manually set AutoField values are now respected; also added unit test to verify the correct behavior. Thanks, cygnus.

Note: See TracTickets for help on using tickets.
Back to Top