mirror of
https://github.com/django/django.git
synced 2025-09-09 12:10:49 +00:00
Fixed #29260 -- Skipped an UPDATE when adding a model instance with primary key that has a default.
This commit is contained in:
parent
e9f74f53cc
commit
85458e94e3
3 changed files with 24 additions and 1 deletions
|
@ -10,7 +10,10 @@ from django.test import (
|
|||
)
|
||||
from django.utils.translation import gettext_lazy
|
||||
|
||||
from .models import Article, ArticleSelectOnSave, FeaturedArticle, SelfRef
|
||||
from .models import (
|
||||
Article, ArticleSelectOnSave, FeaturedArticle, PrimaryKeyWithDefault,
|
||||
SelfRef,
|
||||
)
|
||||
|
||||
|
||||
class ModelInstanceCreationTests(TestCase):
|
||||
|
@ -130,6 +133,11 @@ class ModelInstanceCreationTests(TestCase):
|
|||
# ... but there will often be more efficient ways if that is all you need:
|
||||
self.assertTrue(Article.objects.filter(id=a.id).exists())
|
||||
|
||||
def test_save_primary_with_default(self):
|
||||
# An UPDATE attempt is skipped when a primary key has default.
|
||||
with self.assertNumQueries(1):
|
||||
PrimaryKeyWithDefault().save()
|
||||
|
||||
|
||||
class ModelTest(TestCase):
|
||||
def test_objects_attribute_is_only_available_on_the_class_itself(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue