Fixed #31745 -- Added error messages when using UniqueConstraint.include/opclasses with deferrable.

This commit is contained in:
Hannes Ljungberg 2020-06-29 06:41:23 +02:00 committed by GitHub
parent 62d85a2835
commit 30e3d2d78d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -95,6 +95,14 @@ class UniqueConstraint(BaseConstraint):
raise ValueError( raise ValueError(
'UniqueConstraint with conditions cannot be deferred.' 'UniqueConstraint with conditions cannot be deferred.'
) )
if include and deferrable:
raise ValueError(
'UniqueConstraint with include fields cannot be deferred.'
)
if opclasses and deferrable:
raise ValueError(
'UniqueConstraint with opclasses cannot be deferred.'
)
if not isinstance(deferrable, (type(None), Deferrable)): if not isinstance(deferrable, (type(None), Deferrable)):
raise ValueError( raise ValueError(
'UniqueConstraint.deferrable must be a Deferrable instance.' 'UniqueConstraint.deferrable must be a Deferrable instance.'

View File

@ -406,6 +406,26 @@ class UniqueConstraintTests(TestCase):
deferrable=models.Deferrable.DEFERRED, deferrable=models.Deferrable.DEFERRED,
) )
def test_deferrable_with_include(self):
message = 'UniqueConstraint with include fields cannot be deferred.'
with self.assertRaisesMessage(ValueError, message):
models.UniqueConstraint(
fields=['name'],
name='name_inc_color_color_unique',
include=['color'],
deferrable=models.Deferrable.DEFERRED,
)
def test_deferrable_with_opclasses(self):
message = 'UniqueConstraint with opclasses cannot be deferred.'
with self.assertRaisesMessage(ValueError, message):
models.UniqueConstraint(
fields=['name'],
name='name_text_pattern_ops_unique',
opclasses=['text_pattern_ops'],
deferrable=models.Deferrable.DEFERRED,
)
def test_invalid_defer_argument(self): def test_invalid_defer_argument(self):
message = 'UniqueConstraint.deferrable must be a Deferrable instance.' message = 'UniqueConstraint.deferrable must be a Deferrable instance.'
with self.assertRaisesMessage(ValueError, message): with self.assertRaisesMessage(ValueError, message):