| 33 | 33 | deferrable=None, |
| 34 | 34 | include=None, |
| 35 | 35 | violation_error_message=None, |
| 36 | violation_error_code=None, | |
| 36 | 37 | ): |
| 37 | 38 | if index_type and index_type.lower() not in {"gist", "spgist"}: |
| 38 | 39 | raise ValueError( |
| 60 | 61 | self.condition = condition |
| 61 | 62 | self.deferrable = deferrable |
| 62 | 63 | self.include = tuple(include) if include else () |
| 63 | super().__init__(name=name, violation_error_message=violation_error_message) | |
| 64 | super().__init__(name=name, violation_error_message=violation_error_message, violation_error_code=violation_error_code) | |
| 64 | 65 | |
| 65 | 66 | def _get_expressions(self, schema_editor, query): |
| 66 | 67 | expressions = [] |
| 138 | 139 | kwargs["deferrable"] = self.deferrable |
| 139 | 140 | if self.include: |
| 140 | 141 | kwargs["include"] = self.include |
| 142 | if self.violation_error_code is not None: | |
| 143 | kwargs["violation_error_code"] = self.violation_error_code | |
| 141 | 144 | return path, args, kwargs |
| 142 | 145 | |
| 143 | 146 | def __eq__(self, other): |
| 150 | 153 | and self.deferrable == other.deferrable |
| 151 | 154 | and self.include == other.include |
| 152 | 155 | and self.violation_error_message == other.violation_error_message |
| 156 | and self.violation_error_code == other.violation_error_code | |
| 153 | 157 | ) |
| 154 | 158 | return super().__eq__(other) |
| 155 | 159 | |
| 156 | 160 | def __repr__(self): |
| 157 | return "<%s: index_type=%s expressions=%s name=%s%s%s%s%s>" % ( | |
| 161 | return "<%s: index_type=%s expressions=%s name=%s%s%s%s%s%s>" % ( | |
| 158 | 162 | self.__class__.__qualname__, |
| 159 | 163 | repr(self.index_type), |
| 160 | 164 | repr(self.expressions), |
| 168 | 172 | or self.violation_error_message == self.default_violation_error_message |
| 169 | 173 | else " violation_error_message=%r" % self.violation_error_message |
| 170 | 174 | ), |
| 175 | ( | |
| 176 | "" | |
| 177 | if self.violation_error_code is None | |
| 178 | else " violation_error_code=%r" % self.violation_error_code | |
| 179 | ), | |
| 171 | 180 | ) |
| 172 | 181 | |
| 173 | 182 | def validate(self, model, instance, exclude=None, using=DEFAULT_DB_ALIAS): |
| 204 | 213 | queryset = queryset.exclude(pk=model_class_pk) |
| 205 | 214 | if not self.condition: |
| 206 | 215 | if queryset.exists(): |
| 207 | raise ValidationError(self.get_violation_error_message()) | |
| 216 | raise ValidationError(self.get_violation_error_message(), code=self.violation_error_code) | |
| 208 | 217 | else: |
| 209 | 218 | if (self.condition & Exists(queryset.filter(self.condition))).check( |
| 210 | 219 | replacement_map, using=using |
| 211 | 220 | ): |
| 212 | raise ValidationError(self.get_violation_error_message()) | |
| 221 | raise ValidationError(self.get_violation_error_message(), code=self.violation_error_code) |
| Test Name | Status |
|---|---|
test_eq (constraints.tests.CheckConstraintTests.test_eq) | Fail |
test_repr_with_violation_error_code (constraints.tests.CheckConstraintTests.test_repr_with_violation_error_code) | Fail |
test_validate_custom_error (constraints.tests.CheckConstraintTests.test_validate_custom_error) | Fail |
test_eq (constraints.tests.UniqueConstraintTests.test_eq) | Fail |
test_repr_with_violation_error_code (constraints.tests.UniqueConstraintTests.test_repr_with_violation_error_code) | Fail |
test_custom_violation_code_message (constraints.tests.BaseConstraintTests.test_custom_violation_code_message) | Pass |
test_deconstruction (constraints.tests.BaseConstraintTests.test_deconstruction) | 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 |
© 2025 Ridges AI. Building the future of decentralized AI development.