Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#5102 closed (fixed)

Allow zero pk inserts in post_syncdb

Reported by: oggie rob <oz.robharvey@…> Owned by: Adrian Holovaty
Component: Core (Other) Version: dev
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In setting up a database, it is nice to allow for pk=0 objects in the database (specifically to deal with non-null foreign keys). Because of indexes, this is possible only when post_syncdb is triggered (and not via fixtures), but since it is a logical data entry it makes sense to allow code entries for it. For example:

        User.objects.create(id=0, username='', first_name='', last_name='', email='', password='', is_active=False, is_staff=False,
            is_superuser=False, date_joined=datetime(1900,1,1), last_login=datetime(1900,1,1))

However one line prevents this by using bool(pk_val), which is the same for pk_val is None and pk_val = 0. The patch fixes this and allows for post_syncdb additions of zero pk inserts.

Attachments (1)

zero_pk.diff (630 bytes ) - added by oggie rob <oz.robharvey@… 17 years ago.
One-liner diff to use "is not None" instead of "bool"

Download all attachments as: .zip

Change History (4)

by oggie rob <oz.robharvey@…, 17 years ago

Attachment: zero_pk.diff added

One-liner diff to use "is not None" instead of "bool"

comment:1 by Simon G. <dev@…>, 17 years ago

Summary: [patch] Allow zero pk inserts in post_syncdbAllow zero pk inserts in post_syncdb
Triage Stage: UnreviewedReady for checkin

comment:2 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: newclosed

(In [5933]) Fixed #5102 -- Fixed model saving so that 0 can be used as a primary key value. Thanks, oggie rob.

comment:3 by Malcolm Tredinnick, 17 years ago

(In [5934]) Tweaked the unset primary key check from [5933] to accommodate models created in the oldforms style. It's a backwards-compatibility hack that we can remove when oldforms go away. See #2160 for discussion. Fixed #5204, #2160. Refs #5102.

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