summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias McNulty <tobias@caktusgroup.com>2013-04-08 15:28:15 -0400
committerCarl Meyer <carl@oddbird.net>2013-04-08 13:41:36 -0600
commit161c4da588d4cc757da44bcbb5875a84a7b8a7e6 (patch)
tree0e6292f2d5f220e766e64756fe63ebb15fa95539
parent4a7292df3be2338ff5d915a9ab3107067f662534 (diff)
Fixed #14019 -- Initialize `SQLInsertCompiler.return_id` attribute.
-rw-r--r--django/db/models/sql/compiler.py5
-rw-r--r--tests/model_regress/tests.py12
2 files changed, 17 insertions, 0 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 1f19131ba2..3444b74ac3 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -804,6 +804,11 @@ class SQLCompiler(object):
class SQLInsertCompiler(SQLCompiler):
+
+ def __init__(self, *args, **kwargs):
+ self.return_id = False
+ super(SQLInsertCompiler, self).__init__(*args, **kwargs)
+
def placeholder(self, field, val):
if field is None:
# A field value of None means the value is raw.
diff --git a/tests/model_regress/tests.py b/tests/model_regress/tests.py
index e2d30f0ecc..c1e864c270 100644
--- a/tests/model_regress/tests.py
+++ b/tests/model_regress/tests.py
@@ -7,6 +7,8 @@ from django.core.exceptions import ValidationError
from django.test import TestCase, skipUnlessDBFeature
from django.utils import six
from django.utils import tzinfo
+from django.db import router
+from django.db.models.sql import InsertQuery
from .models import (Worker, Article, Party, Event, Department,
BrokenUnicodeMethod, NonAutoPK, Model1, Model2, Model3)
@@ -27,6 +29,16 @@ class ModelTests(TestCase):
"""
Worker.objects.filter(department__lte=0)
+ def test_sql_insert_compiler_return_id_attribute(self):
+ """
+ Regression test for #14019: SQLInsertCompiler.as_sql() failure
+ """
+ db = router.db_for_write(Party)
+ query = InsertQuery(Party)
+ query.insert_values([Party._meta.fields[0]], [], raw=False)
+ # this line will raise an AttributeError without the accompanying fix
+ query.get_compiler(using=db).as_sql()
+
def test_empty_choice(self):
# NOTE: Part of the regression test here is merely parsing the model
# declaration. The verbose_name, in particular, did not always work.