Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2512 -- Fixed SQL error when saving existing empty models.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3548 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a6a402a7db45ea7d2bb8521b989de573c4f72fee 1 parent cba451c
Malcolm Tredinnick authored August 10, 2006
11  django/db/models/base.py
@@ -176,11 +176,12 @@ def save(self):
176 176
             # If it does already exist, do an UPDATE.
177 177
             if cursor.fetchone():
178 178
                 db_values = [f.get_db_prep_save(f.pre_save(self, False)) for f in non_pks]
179  
-                cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
180  
-                    (backend.quote_name(self._meta.db_table),
181  
-                    ','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
182  
-                    backend.quote_name(self._meta.pk.column)),
183  
-                    db_values + [pk_val])
  179
+                if db_values:
  180
+                    cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
  181
+                        (backend.quote_name(self._meta.db_table),
  182
+                        ','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
  183
+                        backend.quote_name(self._meta.pk.column)),
  184
+                        db_values + [pk_val])
184 185
             else:
185 186
                 record_exists = False
186 187
         if not pk_set or not record_exists:
2  tests/modeltests/empty/models.py
@@ -20,5 +20,7 @@ class Empty(models.Model):
20 20
 2
21 21
 >>> m.id is not None
22 22
 True
  23
+>>> existing = Empty(m.id)
  24
+>>> existing.save()
23 25
 
24 26
 """

0 notes on commit a6a402a

Please sign in to comment.
Something went wrong with that request. Please try again.