1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #32635 -- Fixed system check crash for reverse o2o relations in CheckConstraint.check and UniqueConstraint.condition.

Regression in b7b7df5fbc.

Thanks Szymon Zmilczak for the report.
This commit is contained in:
Hasan Ramezani
2021-04-13 11:51:19 +02:00
committed by Mariusz Felisiak
parent 33abc55601
commit a77c9a4229
3 changed files with 49 additions and 0 deletions

View File

@@ -1694,6 +1694,27 @@ class ConstraintsTests(TestCase):
),
])
@skipUnlessDBFeature('supports_table_check_constraints')
def test_check_constraint_pointing_to_reverse_o2o(self):
class Model(models.Model):
parent = models.OneToOneField('self', models.CASCADE)
class Meta:
constraints = [
models.CheckConstraint(
name='name',
check=models.Q(model__isnull=True),
),
]
self.assertEqual(Model.check(databases=self.databases), [
Error(
"'constraints' refers to the nonexistent field 'model'.",
obj=Model,
id='models.E012',
),
])
@skipUnlessDBFeature('supports_table_check_constraints')
def test_check_constraint_pointing_to_m2m_field(self):
class Model(models.Model):
@@ -1943,6 +1964,28 @@ class ConstraintsTests(TestCase):
)
] if connection.features.supports_partial_indexes else [])
def test_unique_constraint_pointing_to_reverse_o2o(self):
class Model(models.Model):
parent = models.OneToOneField('self', models.CASCADE)
class Meta:
required_db_features = {'supports_partial_indexes'}
constraints = [
models.UniqueConstraint(
fields=['parent'],
name='name',
condition=models.Q(model__isnull=True),
),
]
self.assertEqual(Model.check(databases=self.databases), [
Error(
"'constraints' refers to the nonexistent field 'model'.",
obj=Model,
id='models.E012',
),
] if connection.features.supports_partial_indexes else [])
def test_deferrable_unique_constraint(self):
class Model(models.Model):
age = models.IntegerField()