Loading django/db/models/sql/compiler.py +5 −0 Original line number Diff line number Diff line Loading @@ -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. Loading tests/model_regress/tests.py +12 −0 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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. Loading Loading
django/db/models/sql/compiler.py +5 −0 Original line number Diff line number Diff line Loading @@ -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. Loading
tests/model_regress/tests.py +12 −0 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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. Loading