summaryrefslogtreecommitdiff
path: root/tests/constraints/tests.py
AgeCommit message (Collapse)Author
2026-04-22Fixed #37057 -- Adjusted UniqueConstraint handling of UNKNOWN condition.Simon Charette
When we adjusted UNKNOWN handling for CheckConstraint in refs #33996 we assumed that all usage of Q.check would benefit from this approach. However while CHECK constraints enforcement do ignore conditions involving NULL that resolve to UNKNOWN it's not the case for other type of constraints such as UNIQUE ones. Given how UNKNOWN should be treated depends on the callers context it appears that a better strategy for COALESCE wrapping is to force them to apply it if necessary. Thanks Drew Shapiro for the report.
2025-12-19Fixed #36808 -- Required name argument in UniqueConstraint signature.Jonathan Biemond
By trading ValueError for TypeError for omitted name arguments, we gain a little clarity.
2025-08-04Fixed #34871, #36518 -- Implemented unresolved lookups expression replacement.Simon Charette
This allows the proper resolving of lookups when performing constraint validation involving Q and Case objects. Thanks Andrew Roberts for the report and Sarah for the tests and review.
2025-06-13Fixed #36433 -- Fixed constraint validation crash when condition uses a ↵Colleen Dunlap
ForeignKey attname. Regression in e44e8327d3d88d86895735c0e427102063ff5b55. Thank you to Jacob Walls for the report. Co-authored-by: Simon Charette <charette.s@gmail.com>
2025-03-01Fixed #36198 -- Implemented unresolved transform expression replacement.Simon Charette
This allows the proper resolving of F("field__transform") when performing constraint validation. Thanks Tom Hall for the report and Sarah for the test.
2025-01-15Refs #35234 -- Removed CheckConstraint.check per deprecation timeline.Sarah Boyce
2025-01-15Refs #34355 -- Removed support for positional arguments in BaseConstraint ↵Sarah Boyce
per deprecation timeline.
2024-10-10Fixed #35103 -- Used provided error code and message when fields is set ↵gabn88
without a condition on UniqueConstraint.
2024-08-28Fixed #35666 -- Documented stacklevel usage and testing, and adjusted test ↵Simon Charette
suite accordingly. Over the years we've had multiple instances of hit and misses when emitting warnings: either setting the wrong stacklevel or not setting it at all. This work adds assertions for the existing warnings that were declaring the correct stacklevel, but were lacking tests for it.
2024-08-12Fixed #35575 -- Added support for constraint validation on GeneratedFields.Mark Gensler
2024-08-05Fixed #35638 -- Updated validate_constraints to consider db_default.David Sanders
2024-07-26Added missing skips in constraint tests.Tim Graham
2024-07-17Refs #34701 -- Moved UniqueConstraint(nulls_distinct) validation tests.Simon Charette
The original tests required the creation of a model that is no longer necessary and were exercising Model.full_clean(validate_constraints) which has nothing to do with the nulls_distinct feature.
2024-07-17Fixed #35594 -- Added unique nulls distinct validation for expressions.Simon Charette
Thanks Mark Gensler for the report.
2024-07-17Refs #30581 -- Made unattached UniqueConstraint(fields) validation testable.Simon Charette
The logic allowing UniqueConstraint(fields).validate to preserve backward compatiblity with Model.unique_error_message failed to account for cases where the constraint might not be attached to a model which is a common pattern during testing. This changes allows for arbitrary UniqueConstraint(fields) to be tested in isolation without requiring actual models backing them up. Co-authored-by: Mark G <mark.gensler@protonmail.com>
2024-03-01Refs #35234 -- Deprecated CheckConstraint.check in favor of .condition.Simon Charette
Once the deprecation period ends CheckConstraint.check() can become the documented method that performs system checks for BaseConstraint subclasses.
2024-02-15Fixed #34060 -- Fixed migrations crash when adding check constraints with ↵Albert Defler
JSONField __exact lookup on Oracle.
2023-10-12Refs #34840 -- Fixed test_validate_nullable_textfield_with_isnull_true() on ↵Mariusz Felisiak
databases that don's support table check constraints. Thanks Tim Graham for the report.
2023-09-22Fixed #34840 -- Avoided casting string base fields on PostgreSQL.Mariusz Felisiak
Thanks Alex Vandiver for the report. Regression in 09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca.
2023-08-11Fixed #34743 -- Fixed Meta.constraints validation crash when using pk.Francesco Panico
Thanks Nwawel A Iroume for the report.
2023-08-04Fixed #34754 -- Fixed JSONField check constraints validation on NULL values.Simon Charette
The __isnull lookup of JSONField must special case Value(None, JSONField()) left-hand-side in order to be coherent with its convoluted null handling. Since psycopg>=3 offers no way to pass a NULL::jsonb the issue is resolved by optimizing IsNull(Value(None), True | False) to True | False. Regression in 5c23d9f0c32f166c81ecb6f3f01d5077a6084318. Thanks Alexandre Collet for the report.
2023-07-19Made UniqueConstraint raise TypeError for type violations.Simon Charette
2023-07-19Fixed #34701 -- Added support for NULLS [NOT] DISTINCT on PostgreSQL 15+.Simon Charette
2023-02-24Refs #34338 -- Fixed isolation of constraints tests.Mariusz Felisiak
Regression in 5b3d3e400ab9334ba429ca360c9818c6dfc3a51b.
2023-02-23Fixed #34338 -- Allowed customizing code of ValidationError in ↵Xavier Fernandez
BaseConstraint and subclasses.
2023-02-23Refs #33829 -- Added violation_error_message to constraints' __repr__().Xavier Fernandez
2023-02-22Fixed #34355 -- Deprecated passing positional arguments to BaseConstraint.Xavier Fernandez
2023-02-08Fixed #34319 -- Fixed Model.validate_constraints() crash on ValidationError ↵Mariusz Felisiak
with no code. Thanks Mateusz Kurowski for the report. Regression in 667105877e6723c6985399803a364848891513cc.
2023-01-26Fixed #34291 -- Fixed Meta.constraints validation crash on UniqueConstraint ↵Mariusz Felisiak
with ordered expressions. Thanks Dan F for the report. Bug in 667105877e6723c6985399803a364848891513cc.
2022-09-13Fixed #33996 -- Fixed CheckConstraint validation on NULL values.David Sanders
Bug in 667105877e6723c6985399803a364848891513cc. Thanks James Beith for the report.
2022-08-09Fixed #33902 -- Fixed Meta.constraints validation crash with F() expressions.Mariusz Felisiak
Thanks Adam Zahradník for the report. Bug in 667105877e6723c6985399803a364848891513cc.
2022-07-08Fixed #33829 -- Made BaseConstraint.deconstruct() and equality handle ↵Stéphane "Twidi" Angel
violation_error_message. Regression in 667105877e6723c6985399803a364848891513cc.
2022-05-10Fixed #30581 -- Added support for Meta.constraints validation.Gagaro
Thanks Simon Charette, Keryn Knight, and Mariusz Felisiak for reviews.
2022-05-05Refs #30581 -- Moved CheckConstraint tests for conditional expressions to ↵Mariusz Felisiak
migrations.test_operations. This allows avoiding warning in tests about using RawSQL in CheckConstraints.
2022-02-07Refs #33476 -- Reformatted code with Black.django-bot
2021-02-23Fixed #30916 -- Added support for functional unique constraints.Hannes Ljungberg
Thanks Ian Foote and Mariusz Felisiak for reviews.
2021-02-19Fixed #32458 -- Made __repr__() for Index and BaseConstraint subclasses more ↵Hannes Ljungberg
consistent.
2020-07-27Fixed #31815 -- Fixed schema value encoding on PostgreSQL.Mariusz Felisiak
2020-06-29Fixed #31745 -- Added error messages when using ↵Hannes Ljungberg
UniqueConstraint.include/opclasses with deferrable.
2020-06-16Fixed #31702 -- Added support for PostgreSQL opclasses in UniqueConstraint.Hannes Ljungberg
2020-06-04Fixed #30913 -- Added support for covering indexes on PostgreSQL 11+.Hannes Ljungberg
2020-04-30Fixed #20581 -- Added support for deferrable unique constraints.Ian Foote
2020-04-17Refs #31351 -- Made partial constraints tests use required_db_features.Mariusz Felisiak
This will notably silence the warnings issued when running the test suite on MySQL and MariaDB.
2019-11-21Fixed #30484 -- Added conditional expressions support to CheckConstraint.Simon Charette
2019-10-01Fixed #30651 -- Made __eq__() methods return NotImplemented for not ↵ElizabethU
implemented comparisons. Changed __eq__ to return NotImplemented instead of False if compared to an object of the same type, as is recommended by the Python data model reference. Now these models can be compared to ANY (or other objects with __eq__ overwritten) without returning False automatically.
2019-08-12Refs #11964 -- Made constraint support check respect required_db_features.Simon Charette
This will notably silence the warnings issued when running the test suite on MySQL.
2019-07-19Fixed #30593 -- Added support for check constraints on MariaDB 10.2+.Hasan Ramezani
2019-07-08Fixed #30397 -- Added app_label/class interpolation for names of indexes and ↵can
constraints.
2019-01-12Fixed #30062 -- Added support for unique conditional constraints.Paveł Tyślacki
2019-01-12Added tests for Check/UniqueConstraint.__eq__().Paveł Tyślacki