mirror of https://github.com/django/django.git
Made UniqueConstraint raise TypeError for type violations.
This commit is contained in:
parent
595a2abb58
commit
d7d80040c1
|
@ -217,15 +217,15 @@ class UniqueConstraint(BaseConstraint):
|
|||
"Use django.contrib.postgres.indexes.OpClass() instead."
|
||||
)
|
||||
if not isinstance(deferrable, (NoneType, Deferrable)):
|
||||
raise ValueError(
|
||||
raise TypeError(
|
||||
"UniqueConstraint.deferrable must be a Deferrable instance."
|
||||
)
|
||||
if not isinstance(include, (NoneType, list, tuple)):
|
||||
raise ValueError("UniqueConstraint.include must be a list or tuple.")
|
||||
raise TypeError("UniqueConstraint.include must be a list or tuple.")
|
||||
if not isinstance(opclasses, (list, tuple)):
|
||||
raise ValueError("UniqueConstraint.opclasses must be a list or tuple.")
|
||||
raise TypeError("UniqueConstraint.opclasses must be a list or tuple.")
|
||||
if not isinstance(nulls_distinct, (NoneType, bool)):
|
||||
raise ValueError("UniqueConstraint.nulls_distinct must be a bool.")
|
||||
raise TypeError("UniqueConstraint.nulls_distinct must be a bool.")
|
||||
if opclasses and len(fields) != len(opclasses):
|
||||
raise ValueError(
|
||||
"UniqueConstraint.fields and UniqueConstraint.opclasses must "
|
||||
|
|
|
@ -1046,7 +1046,7 @@ class UniqueConstraintTests(TestCase):
|
|||
|
||||
def test_invalid_defer_argument(self):
|
||||
message = "UniqueConstraint.deferrable must be a Deferrable instance."
|
||||
with self.assertRaisesMessage(ValueError, message):
|
||||
with self.assertRaisesMessage(TypeError, message):
|
||||
models.UniqueConstraint(
|
||||
fields=["name"],
|
||||
name="name_invalid",
|
||||
|
@ -1064,7 +1064,7 @@ class UniqueConstraintTests(TestCase):
|
|||
|
||||
def test_invalid_include_argument(self):
|
||||
msg = "UniqueConstraint.include must be a list or tuple."
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
models.UniqueConstraint(
|
||||
name="uniq_include",
|
||||
fields=["field"],
|
||||
|
@ -1073,7 +1073,7 @@ class UniqueConstraintTests(TestCase):
|
|||
|
||||
def test_invalid_opclasses_argument(self):
|
||||
msg = "UniqueConstraint.opclasses must be a list or tuple."
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
models.UniqueConstraint(
|
||||
name="uniq_opclasses",
|
||||
fields=["field"],
|
||||
|
@ -1082,7 +1082,7 @@ class UniqueConstraintTests(TestCase):
|
|||
|
||||
def test_invalid_nulls_distinct_argument(self):
|
||||
msg = "UniqueConstraint.nulls_distinct must be a bool."
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
models.UniqueConstraint(
|
||||
name="uniq_opclasses", fields=["field"], nulls_distinct="NULLS DISTINCT"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue