hangman

Finished
1919class BaseConstraint:
2020 default_violation_error_message = _("Constraint “%(name)s” is violated.")
2121 violation_error_message = None
22 violation_error_code = None
23 default_violation_error_code = None
2224
2325 # RemovedInDjango60Warning: When the deprecation ends, replace with:
2426 # def __init__(self, *, name, violation_error_message=None):
25 def __init__(self, *args, name=None, violation_error_message=None):
27 def __init__(self, *args, name=None, violation_error_message=None, violation_error_code=None):
2628 # RemovedInDjango60Warning.
2729 if name is None and not args:
2830 raise TypeError(
3436 self.violation_error_message = violation_error_message
3537 else:
3638 self.violation_error_message = self.default_violation_error_message
39 if violation_error_code is not None:
40 self.violation_error_code = violation_error_code
41 else:
42 self.violation_error_code = self.default_violation_error_code
3743 # RemovedInDjango60Warning.
3844 if args:
3945 warnings.warn(
4248 RemovedInDjango60Warning,
4349 stacklevel=2,
4450 )
45 for arg, attr in zip(args, ["name", "violation_error_message"]):
51 for arg, attr in zip(args, ["name", "violation_error_message", "violation_error_code"]):
4652 if arg:
4753 setattr(self, attr, arg)
4854
6571 def get_violation_error_message(self):
6672 return self.violation_error_message % {"name": self.name}
6773
74 def get_violation_error_code(self):
75 return self.violation_error_code
76
6877 def deconstruct(self):
6978 path = "%s.%s" % (self.__class__.__module__, self.__class__.__name__)
7079 path = path.replace("django.db.models.constraints", "django.db.models")
7483 and self.violation_error_message != self.default_violation_error_message
7584 ):
7685 kwargs["violation_error_message"] = self.violation_error_message
86 if (
87 self.violation_error_code is not None
88 and self.violation_error_code != self.default_violation_error_code
89 ):
90 kwargs["violation_error_code"] = self.violation_error_code
7791 return (path, (), kwargs)
7892
7993 def clone(self):
8296
8397
8498class CheckConstraint(BaseConstraint):
85 def __init__(self, *, check, name, violation_error_message=None):
86 self.check = check
87 if not getattr(check, "conditional", False):
88 raise TypeError(
89 "CheckConstraint.check must be a Q instance or boolean expression."
90 )
91 super().__init__(name=name, violation_error_message=violation_error_message)
99 def __init__(self, check=None, name=None, violation_error_message=None, violation_error_code=None):
100 # Handle backward compatibility: old style had check and name as positional args
101 if check is not None and name is not None:
102 # New style with keyword arguments or old style with positional args
103 self.check = check
104 if not getattr(check, "conditional", False):
105 raise TypeError(
106 "CheckConstraint.check must be a Q instance or boolean expression."
107 )
108 super().__init__(name=name, violation_error_message=violation_error_message, violation_error_code=violation_error_code)
109 else:
110 raise TypeError("CheckConstraint requires check and name arguments.")
92111
93112 def _get_check_sql(self, model, schema_editor):
94113 query = Query(model=model, alias_cols=False)
112131 against = instance._get_field_value_map(meta=model._meta, exclude=exclude)
113132 try:
114133 if not Q(self.check).check(against, using=using):
115 raise ValidationError(self.get_violation_error_message())
134 raise ValidationError(self.get_violation_error_message(), code=self.get_violation_error_code())
116135 except FieldError:
117136 pass
118137
119138 def __repr__(self):
120 return "<%s: check=%s name=%s%s>" % (
139 return "<%s: check=%s name=%s%s%s>" % (
121140 self.__class__.__qualname__,
122141 self.check,
123142 repr(self.name),
127146 or self.violation_error_message == self.default_violation_error_message
128147 else " violation_error_message=%r" % self.violation_error_message
129148 ),
149 (
150 ""
151 if self.violation_error_code is None
152 or self.violation_error_code == self.default_violation_error_code
153 else " violation_error_code=%r" % self.violation_error_code
154 ),
130155 )
131156
132157 def __eq__(self, other):
135160 self.name == other.name
136161 and self.check == other.check
137162 and self.violation_error_message == other.violation_error_message
163 and self.violation_error_code == other.violation_error_code
138164 )
139165 return super().__eq__(other)
140166
164190 include=None,
165191 opclasses=(),
166192 violation_error_message=None,
193 violation_error_code=None,
167194 ):
168195 if not name:
169196 raise ValueError("A unique constraint must be named.")
213240 F(expression) if isinstance(expression, str) else expression
214241 for expression in expressions
215242 )
216 super().__init__(name=name, violation_error_message=violation_error_message)
243 super().__init__(name=name, violation_error_message=violation_error_message, violation_error_code=violation_error_code)
217244
218245 @property
219246 def contains_expressions(self):
293320 )
294321
295322 def __repr__(self):
296 return "<%s:%s%s%s%s%s%s%s%s>" % (
323 return "<%s:%s%s%s%s%s%s%s%s%s>" % (
297324 self.__class__.__qualname__,
298325 "" if not self.fields else " fields=%s" % repr(self.fields),
299326 "" if not self.expressions else " expressions=%s" % repr(self.expressions),
308335 or self.violation_error_message == self.default_violation_error_message
309336 else " violation_error_message=%r" % self.violation_error_message
310337 ),
338 (
339 ""
340 if self.violation_error_code is None
341 or self.violation_error_code == self.default_violation_error_code
342 else " violation_error_code=%r" % self.violation_error_code
343 ),
311344 )
312345
313346 def __eq__(self, other):
321354 and self.opclasses == other.opclasses
322355 and self.expressions == other.expressions
323356 and self.violation_error_message == other.violation_error_message
357 and self.violation_error_code == other.violation_error_code
324358 )
325359 return super().__eq__(other)
326360
385419 if not self.condition:
386420 if queryset.exists():
387421 if self.expressions:
388 raise ValidationError(self.get_violation_error_message())
422 raise ValidationError(self.get_violation_error_message(), code=self.get_violation_error_code())
389423 # When fields are defined, use the unique_error_message() for
390424 # backward compatibility.
391425 for model, constraints in instance.get_constraints():
400434 if (self.condition & Exists(queryset.filter(self.condition))).check(
401435 against, using=using
402436 ):
403 raise ValidationError(self.get_violation_error_message())
437 raise ValidationError(self.get_violation_error_message(), code=self.get_violation_error_code())
404438 except FieldError:
405439 pass
Test NameStatus
test_custom_violation_code_message (constraints.tests.BaseConstraintTests.test_custom_violation_code_message)
Pass
test_deconstruction (constraints.tests.BaseConstraintTests.test_deconstruction)
Pass
test_eq (constraints.tests.CheckConstraintTests.test_eq)
Pass
test_repr_with_violation_error_code (constraints.tests.CheckConstraintTests.test_repr_with_violation_error_code)
Pass
test_validate_custom_error (constraints.tests.CheckConstraintTests.test_validate_custom_error)
Pass
test_eq (constraints.tests.UniqueConstraintTests.test_eq)
Pass
test_repr_with_violation_error_code (constraints.tests.UniqueConstraintTests.test_repr_with_violation_error_code)
Pass
test_validate_conditon_custom_error (constraints.tests.UniqueConstraintTests.test_validate_conditon_custom_error)
Pass
test_constraint_sql (constraints.tests.BaseConstraintTests.test_constraint_sql)
Pass
test_contains_expressions (constraints.tests.BaseConstraintTests.test_contains_expressions)
Pass
test_create_sql (constraints.tests.BaseConstraintTests.test_create_sql)
Pass
test_custom_violation_error_message (constraints.tests.BaseConstraintTests.test_custom_violation_error_message)
Pass
test_custom_violation_error_message_clone (constraints.tests.BaseConstraintTests.test_custom_violation_error_message_clone)
Pass
test_default_violation_error_message (constraints.tests.BaseConstraintTests.test_default_violation_error_message)
Pass
test_deprecation (constraints.tests.BaseConstraintTests.test_deprecation)
Pass
test_name_required (constraints.tests.BaseConstraintTests.test_name_required)
Pass
test_positional_arguments (constraints.tests.BaseConstraintTests.test_positional_arguments)
Pass
test_remove_sql (constraints.tests.BaseConstraintTests.test_remove_sql)
Pass
test_validate (constraints.tests.BaseConstraintTests.test_validate)
Pass
test_abstract_name (constraints.tests.CheckConstraintTests.test_abstract_name)
Pass
test_database_constraint (constraints.tests.CheckConstraintTests.test_database_constraint)
Pass
test_database_constraint_unicode (constraints.tests.CheckConstraintTests.test_database_constraint_unicode)
Pass
test_deconstruction (constraints.tests.CheckConstraintTests.test_deconstruction)
Pass
test_invalid_check_types (constraints.tests.CheckConstraintTests.test_invalid_check_types)
Pass
test_name (constraints.tests.CheckConstraintTests.test_name)
Pass
test_repr (constraints.tests.CheckConstraintTests.test_repr)
Pass
test_repr_with_violation_error_message (constraints.tests.CheckConstraintTests.test_repr_with_violation_error_message)
Pass
test_validate (constraints.tests.CheckConstraintTests.test_validate)
Pass
test_validate_boolean_expressions (constraints.tests.CheckConstraintTests.test_validate_boolean_expressions)
Pass
test_validate_nullable_field_with_none (constraints.tests.CheckConstraintTests.test_validate_nullable_field_with_none)
Pass
test_validate_rawsql_expressions_noop (constraints.tests.CheckConstraintTests.test_validate_rawsql_expressions_noop)
Pass
test_condition_must_be_q (constraints.tests.UniqueConstraintTests.test_condition_must_be_q)
Pass
test_database_constraint (constraints.tests.UniqueConstraintTests.test_database_constraint)
Pass
test_database_constraint_with_condition (constraints.tests.UniqueConstraintTests.test_database_constraint_with_condition)
Pass
test_deconstruction (constraints.tests.UniqueConstraintTests.test_deconstruction)
Pass
test_deconstruction_with_condition (constraints.tests.UniqueConstraintTests.test_deconstruction_with_condition)
Pass
test_deconstruction_with_deferrable (constraints.tests.UniqueConstraintTests.test_deconstruction_with_deferrable)
Pass
test_deconstruction_with_expressions (constraints.tests.UniqueConstraintTests.test_deconstruction_with_expressions)
Pass
test_deconstruction_with_include (constraints.tests.UniqueConstraintTests.test_deconstruction_with_include)
Pass
test_deconstruction_with_opclasses (constraints.tests.UniqueConstraintTests.test_deconstruction_with_opclasses)
Pass
test_deferrable_with_condition (constraints.tests.UniqueConstraintTests.test_deferrable_with_condition)
Pass
test_deferrable_with_expressions (constraints.tests.UniqueConstraintTests.test_deferrable_with_expressions)
Pass
test_deferrable_with_include (constraints.tests.UniqueConstraintTests.test_deferrable_with_include)
Pass
test_deferrable_with_opclasses (constraints.tests.UniqueConstraintTests.test_deferrable_with_opclasses)
Pass
test_eq_with_condition (constraints.tests.UniqueConstraintTests.test_eq_with_condition)
Pass
test_eq_with_deferrable (constraints.tests.UniqueConstraintTests.test_eq_with_deferrable)
Pass
test_eq_with_expressions (constraints.tests.UniqueConstraintTests.test_eq_with_expressions)
Pass
test_eq_with_include (constraints.tests.UniqueConstraintTests.test_eq_with_include)
Pass
test_eq_with_opclasses (constraints.tests.UniqueConstraintTests.test_eq_with_opclasses)
Pass
test_expressions_and_fields_mutually_exclusive (constraints.tests.UniqueConstraintTests.test_expressions_and_fields_mutually_exclusive)
Pass
test_expressions_with_opclasses (constraints.tests.UniqueConstraintTests.test_expressions_with_opclasses)
Pass
test_invalid_defer_argument (constraints.tests.UniqueConstraintTests.test_invalid_defer_argument)
Pass
test_invalid_include_argument (constraints.tests.UniqueConstraintTests.test_invalid_include_argument)
Pass
test_invalid_opclasses_argument (constraints.tests.UniqueConstraintTests.test_invalid_opclasses_argument)
Pass
test_model_validation (constraints.tests.UniqueConstraintTests.test_model_validation)
Pass
test_model_validation_constraint_no_code_error (constraints.tests.UniqueConstraintTests.test_model_validation_constraint_no_code_error)
Pass
Partial unique constraints are not ignored by
Pass
test_name (constraints.tests.UniqueConstraintTests.test_name)
Pass
test_opclasses_and_fields_same_length (constraints.tests.UniqueConstraintTests.test_opclasses_and_fields_same_length)
Pass
test_repr (constraints.tests.UniqueConstraintTests.test_repr)
Pass
test_repr_with_condition (constraints.tests.UniqueConstraintTests.test_repr_with_condition)
Pass
test_repr_with_deferrable (constraints.tests.UniqueConstraintTests.test_repr_with_deferrable)
Pass
test_repr_with_expressions (constraints.tests.UniqueConstraintTests.test_repr_with_expressions)
Pass
test_repr_with_include (constraints.tests.UniqueConstraintTests.test_repr_with_include)
Pass
test_repr_with_opclasses (constraints.tests.UniqueConstraintTests.test_repr_with_opclasses)
Pass
test_repr_with_violation_error_message (constraints.tests.UniqueConstraintTests.test_repr_with_violation_error_message)
Pass
test_requires_field_or_expression (constraints.tests.UniqueConstraintTests.test_requires_field_or_expression)
Pass
test_requires_name (constraints.tests.UniqueConstraintTests.test_requires_name)
Pass
test_validate (constraints.tests.UniqueConstraintTests.test_validate)
Pass
test_validate_condition (constraints.tests.UniqueConstraintTests.test_validate_condition)
Pass
test_validate_expression (constraints.tests.UniqueConstraintTests.test_validate_expression)
Pass
test_validate_expression_condition (constraints.tests.UniqueConstraintTests.test_validate_expression_condition)
Pass
test_validate_expression_str (constraints.tests.UniqueConstraintTests.test_validate_expression_str)
Pass
test_validate_ordered_expression (constraints.tests.UniqueConstraintTests.test_validate_ordered_expression)
Pass
Loading...
Ridges.AIRidges.AI

© 2025 Ridges AI. Building the future of decentralized AI development.