summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-06-08 00:13:52 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-06-08 00:13:52 +0000
commit89920e058fcb673ff82ae67a41566216895c8bd3 (patch)
treee9f37dc294987c1a61211726f3c6099dd2ad9466 /django
parent58ab678d354a04bcbf0a568f1950a4f41efbae12 (diff)
Fixed #2108 -- do not try to save an empty model.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3104 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/models/base.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 3538826356..68e805e003 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -183,11 +183,12 @@ class Model(object):
placeholders.append('(SELECT COUNT(*) FROM %s WHERE %s = %%s)' % \
(backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.order_with_respect_to.column)))
db_values.append(getattr(self, self._meta.order_with_respect_to.attname))
- cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \
- (backend.quote_name(self._meta.db_table), ','.join(field_names),
- ','.join(placeholders)), db_values)
- if self._meta.has_auto_field and not pk_set:
- setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column))
+ if db_values:
+ cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \
+ (backend.quote_name(self._meta.db_table), ','.join(field_names),
+ ','.join(placeholders)), db_values)
+ if self._meta.has_auto_field and not pk_set:
+ setattr(self, self._meta.pk.attname, backend.get_last_insert_id(cursor, self._meta.db_table, self._meta.pk.column))
transaction.commit_unless_managed()
# Run any post-save hooks.