From 390e91db51ee48645a84117bfdcafce2744b5181 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 19 Aug 2007 03:23:31 +0000 Subject: [PATCH] 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. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5934 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index 064dc8fdec..1a0de4c827 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -209,7 +209,9 @@ class Model(object): # First, try an UPDATE. If that doesn't update anything, do an INSERT. pk_val = self._get_pk_val() - pk_set = pk_val is not None + # Note: the comparison with '' is required for compatibility with + # oldforms-style model creation. + pk_set = pk_val is not None and pk_val != u'' record_exists = True if pk_set: # Determine whether a record with the primary key already exists.