1
0
mirror of https://github.com/django/django.git synced 2025-03-06 07:22:32 +00:00

Refs #36064 -- Added test that falsey primary key default/db_default value skips an update query on save.

This adds test coverage for logic change in 9fa4d07ce0729850661a31a6b37c6b48f13d2266.
This commit is contained in:
Bendeguz Csirmaz 2025-01-10 08:44:10 +01:00 committed by Sarah Boyce
parent 9fa4d07ce0
commit 8287fd4915
2 changed files with 18 additions and 0 deletions

View File

@ -57,5 +57,13 @@ class PrimaryKeyWithDbDefault(models.Model):
uuid = models.IntegerField(primary_key=True, db_default=1)
class PrimaryKeyWithFalseyDefault(models.Model):
uuid = models.IntegerField(primary_key=True, default=0)
class PrimaryKeyWithFalseyDbDefault(models.Model):
uuid = models.IntegerField(primary_key=True, db_default=0)
class ChildPrimaryKeyWithDefault(PrimaryKeyWithDefault):
pass

View File

@ -32,6 +32,8 @@ from .models import (
FeaturedArticle,
PrimaryKeyWithDbDefault,
PrimaryKeyWithDefault,
PrimaryKeyWithFalseyDbDefault,
PrimaryKeyWithFalseyDefault,
SelfRef,
)
@ -203,6 +205,14 @@ class ModelInstanceCreationTests(TestCase):
with self.assertNumQueries(2):
ChildPrimaryKeyWithDefault().save()
def test_save_primary_with_falsey_default(self):
with self.assertNumQueries(1):
PrimaryKeyWithFalseyDefault().save()
def test_save_primary_with_falsey_db_default(self):
with self.assertNumQueries(1):
PrimaryKeyWithFalseyDbDefault().save()
def test_save_deprecation(self):
a = Article(headline="original", pub_date=datetime(2014, 5, 16))
msg = "Passing positional arguments to save() is deprecated"