Skip to content

Commit

Permalink
Fixed #2512 -- Fixed SQL error when saving existing empty models.
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3548 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Aug 10, 2006
1 parent cba451c commit a6a402a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions django/db/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ def save(self):
# If it does already exist, do an UPDATE.
if cursor.fetchone():
db_values = [f.get_db_prep_save(f.pre_save(self, False)) for f in non_pks]
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
(backend.quote_name(self._meta.db_table),
','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
backend.quote_name(self._meta.pk.column)),
db_values + [pk_val])
if db_values:
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
(backend.quote_name(self._meta.db_table),
','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
backend.quote_name(self._meta.pk.column)),
db_values + [pk_val])
else:
record_exists = False
if not pk_set or not record_exists:
Expand Down
2 changes: 2 additions & 0 deletions tests/modeltests/empty/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ class Empty(models.Model):
2
>>> m.id is not None
True
>>> existing = Empty(m.id)
>>> existing.save()
"""

0 comments on commit a6a402a

Please sign in to comment.