summaryrefslogtreecommitdiff
path: root/tests/model_fields
AgeCommit message (Collapse)Author
2026-10-28Fixed #37089 -- Made ignore_warnings() match substrings by default.HelmiDev03
Thank you Mike Edmunds for the review.
2026-10-23Refs #30949 -- Replaced django.utils.functional.cached_property with ↵Jacob Rief
functools.cached_property. Since Python 3.12, `functools.cached_property` no longer takes a lock (https://github.com/python/cpython/issues/87634), which was the main objection to using it instead of Django's own implementation. `Prefetch(to_attr=...)` and the admindocs model detail page now accept `functools.cached_property` as well as Django's own `cached_property`. Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
2026-10-21Fixed #37407 -- Prevented UUIDTextMixin from mutating the lookup in-place.Clifford Gama
2026-10-08Fixed #37403 -- Fixed JSONField __in crash on SQLite with Value(None) ↵Clifford Gama
expressions. Regression in 9b8e4c6d7d47f7b2e96817ba334e9fd53c10a0df.
2026-10-07Refs #37297 -- Prevented crash on JSONField __isnull lookups on Oracle when ↵Clifford Gama
a key is outside its integer range. Oracle's JSON_EXISTS() rejects an array-subscript literal this long with ORA-40598/JZN-00211.
2026-10-07Fixed #37297 -- Prevented crash on JSONField key lookups when an integer key ↵Clifford Gama
is outside PostgreSQL's int4 range.
2026-10-05Fixed #37377 -- Fixed JSONField __in crash/wrong result for Value() primitives.Clifford Gama
Refs #36689. 9b8e4c6d7d wrapped every Value() rhs param of a JSONIn lookup in JSON_EXTRACT()/JSON_VALUE() assuming it was already JSON-serialized. That only holds for Value(..., JSONField()); a bare Value("primitive") gets an inferred non-JSON output_field (e.g. CharField), so its compiled param was a raw primitive, not JSON text. JSONIn.resolve_expression_parameter() now JSON-encodes the Value's raw .value itself whenever its output_field isn't JSONField. As a side effect, this also fixes Value(True)/Value(False) in __in, which were previously compared as raw Python bools against the JSON-extracted lhs and never matched. Thanks Jacob Walls for the report. Regression in 9b8e4c6d7d47f7b2e96817ba334e9fd53c10a0df. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
2026-09-18Fixed #37339 -- Allowed ipaddress objects in GenericIPAddressField.Thibaut Decombe
get_prep_value() tested for ":" before coercing the value to a string, which crashed with a TypeError for non-string values such as ipaddress.IPv4Address and ipaddress.IPv6Address instances, even though to_python() accepts them.
2026-09-17Refs #37348 -- Added test for excluding on a nullable GeneratedField.Natalia
Negated lookups rely on `Field.null` to match rows where the value is `NULL`. This behavior was lost when `null=True` was removed from `GeneratedField` definitions to silence `fields.W225`.
2026-09-17Refs #37348 -- Reverted "Refs #36806 -- Removed unnecessary null=True from ↵Natalia
GeneratedField in test models.". This reverts commit 968f3f96373e028f1486d135e38331fcd0e3a0ca.
2026-09-03Refs #37293 -- Aliased RemovedInDjango70Warning to RemovedInDjango2028Warning.Carlton Gibson
Updated references to RemovedInDjango70Warning to use the new warning, and adjusted references to "Django 7.0" to "Django 2028". RemovedInDjango70Warning remains importable as an alias of the same class, so existing warning filters and except clauses in third-party code keep working across the rename.
2026-08-27Fixed #37255 -- Avoided relying on implicit SELECT ordering in tests.viralpraxis
Many (~70) tests assert a specific row order for querysets whose SQL has no ORDER BY. SQL standard does not define that order. On PostgreSQL the rows usually arrive in physical storage order, which on a freshly loaded table matches insertion order -- so these assertions pass by coincidence rather than by contract. That breaks when rows are updated or deleted and the space is reused, or when the planner picks a different access path such as an index scan. A test like this can start failing with no change to Django or to the test itself. The patch made sure that most of these tests do not rely on unspecified unordered selection order.
2026-08-17Fixed #37275, Refs #24920 -- Fixed SQLite DecimalField conversion without ↵Sarah Boyce
precision. Thank you Matt Cooper for the report and Mariusz Felisiak for the review.
2026-05-11Fixed #36593 -- Deprecated QuerySet.select_related() with no arguments.Adam Johnson
This commit deprecates the "fetch all relations" form of `QuerySet.select_related()` due to its poor performance characteristics, and updates several tests relying on that feature to ignore the new warning.
2026-05-05Fixed #37053 -- Added validate=True to base64.b64decode() calls.Sarah Boyce
2026-04-22Fixed #35870 -- Made blank choice label in forms more accessible.Annabelle Wiegart
Added new constant django.db.models.fields.BLANK_CHOICE_LABEL for an accessible and translatable blank choice label in forms. Deprecated django.db.models.fields.BLANK_CHOICE_DASH constant. Added the immediately deprecated transitional setting USE_BLANK_CHOICE_DASH. Co-Authored-By: Marijke Luttekes <mail@marijkeluttekes.dev>
2026-03-24Refs #36494 -- Prevented crash in JSONField numeric lookups with expressions.Vignesh Anand
2026-03-16Fixed #36906 -- Handled coalescing JSON-primitive strings and JSON values on ↵Kanin Kearpimy
Oracle.
2026-03-12Fixed #36727 -- Deprecated Field.get_placeholder in favor of ↵Simon Charette
get_placeholder_sql. The lack of ability of the get_placeholder call chain to return SQL and parameters separated so they can be mogrified by the backend at execution time forced implementations to dangerously interpolate potentially user controlled values. The get_placeholder_sql name was chosen due to its proximity to the previous method, but other options such as Field.as_sql were considered but ultimately rejected due to its different input signature compared to Expression.as_sql that might have lead to confusion. There is a lot of overlap between what Field.get_db_prep_value and get_placeholder_sql do but folding the latter in the former would require changing its return signature to return expression which is a way more invasive change than what is proposed here. Given we always call get_db_prep_value it might still be an avenue worth exploring in the future to offer a publicly documented interface to allow field to take an active part in the compilation chain. Thanks Jacob for the review.
2026-01-29Fixed #36847 -- Ensured auto_now_add fields are set on pre_save().Nilesh Kumar Pahari
Regression in 94680437a45a71c70ca8bd2e68b72aa1e2eff337. Refs #27222. During INSERT operations, `field.pre_save()` is called to prepare values for db insertion. The `add` param must be `True` for `auto_now_add` fields to be populated. The regression commit passed `False`, causing `auto_now_add` fields to remain `None` when used by other fields, such as `upload_to` callables. Thanks Ran Benita for the report.
2026-01-28Fixed #36233 -- Avoided quantizing integers stored in DecimalField on SQLite.Samriddha9619
Co-authored-by: Simon Charette <charette.s@gmail.com> Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
2025-12-22Refs #36806 -- Removed unnecessary null=True from GeneratedField in test models.Nilesh Kumar Pahari
Test coverage is preserved because the tests only verify that generated fields can produce NULL values when the source field is nullable. This addresses system check warnings in the test suite after 6025eab3c509b4de922117e16866bbfe0ee99aa6.
2025-12-22Fixed #36508 -- Interpreted __iexact=None on KeyTransforms as __exact=None.Clifford Gama
Thanks Jacob Walls for the report.
2025-12-22Replaced per-object create() calls with bulk_create in ↵Clifford Gama
tests/model_fields/test_jsonfield.py
2025-12-13Fixed #36765 -- Added support for stored GeneratedFields on Oracle 23ai/26ai ↵Mariusz Felisiak
(23.7+). Thanks Jacob Walls for the review.
2025-12-10Refs #36025 -- Made get_prep_lookup() pass output_field when wrapping direct ↵Clifford Gama
values in Value. Previously, only strings were supplied with an output_field when wrapping direct value iterable elements in Value expressions for ExpressionList. This caused problems for __in lookups on JSONField when using expressions alongside direct values, as JSONField values can have different types which need to be adapted by the field's get_db_prep_value(). Refs #36689. Thanks Jacob Walls for the review.
2025-12-10Refs #36689 -- Serialized JSONIn rhs parameters wrapped in Value expressions.Clifford Gama
2025-12-10Fixed #36689 -- Fixed top-level JSONField __in lookup failures on MySQL and ↵Clifford Gama
Oracle. Added a JSONIn lookup to handle correct serialization and extraction for JSONField top-level __in queries on backends without native JSON support. KeyTransformIn now subclasses JSONIn. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com> Thanks Jacob Walls for the report and review.
2025-11-12Refs #35381 -- Made JSONNull deconstruct using convenient import path.Clifford Gama
2025-10-29Refs #35381 -- Deprecated using None in JSONExact rhs to mean JSON null.Clifford Gama
Key and index lookups are exempt from the deprecation. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
2025-10-29Fixed #35381 -- Added JSONNull() expression.Clifford Gama
Thanks Jacob Walls for the review.
2025-10-13Removed reference to "manager" in ForeignKeyTests.Jacob Walls
Follow-up to 0de89b6f8d4d8f5fd232d6c5412260b0d79a760a.
2025-09-22Fixed #35453 -- Made ManyToManyField.concrete False.Ryan P Kilby
ManyToManyField was already excluded from fields, concrete_fields, and local_concrete_fields in Options.
2025-09-22Fixed #36612 -- Fixed a KeyTextTransform crash on MySQL against annotations.Simon Charette
MySQL only supports the ->> when used directly against columns, this can be inferred by the presence of lhs.output_field.model as model bounds fields are directly tied to columns. Purposely don't systematically switch to using JSON_QUOTE(JSON_EXTRACT(...)) as there might be functional indices out there that rely on the SQL remaining stable between versions. Thanks Jacob Tavener for the report.
2025-09-14Refs #27222 -- Refreshed GeneratedFields values on save() initiated update.Simon Charette
This required implementing UPDATE RETURNING machinery that heavily borrows from the INSERT one.
2025-07-23Removed double spaces after periods and within phrases.Sarah Boyce
2025-05-16Fixed #33312 -- Raised explicit exception when copying deferred model instances.Simon Charette
Previously save() would crash with an attempted forced update message, and both save(force_insert=True) and bulk_create() would crash with DoesNotExist errors trying to retrieve rows with an empty primary key (id IS NULL). Implementing deferred field model instance copying might be doable in certain cases (e.g. when all the deferred fields are db generated) but that's not trivial to implement in a backward compatible way. Thanks Adam Sołtysik for the report and test and Clifford for the review.
2025-05-14Fixed #36085 -- Added JSONField support for negative array indexing on SQLite.savanto
2025-03-25Fixed #36262 -- Made GeneratedField.db_persist a required key-word argument.Jason Cameron
2025-03-01Applied Black's 2025 stable style.Mariusz Felisiak
https://github.com/psf/black/releases/tag/25.1.0
2025-02-27Refs #35617 -- Removed hardcoded pk in test_bulk_update_custom_get_prep_value().Jacob Walls
2025-02-20Refs #35167 -- Fixed test_bulk_update_custom_get_prep_value() crash on ↵Mariusz Felisiak
databases that don't support primitives in JSONFields. For example on Oracle < 21c.
2025-02-18Fixed #35167 -- Delegated to super() in JSONField.get_db_prep_save().Jacob Walls
Avoids reports of bulk_update() sending Cast expressions to JSONField.get_prep_value(). Co-authored-by: Simon Charette <charette.s@gmail.com>
2025-02-06Fixed #36025 -- Fixed re-aliasing of iterable (in/range) lookups rhs.Simon Charette
In order for Expression.relabeled_clone to work appropriately its get_source_expressions method must return all resolvable which wasn't the case for Lookup when its right-hand-side is "direct" (not a compilable). While refs #22288 added support for non-literals iterable right-hand-side lookups it predated the subclassing of Lookup(Expression) refs #27021 which could have been an opportunity to ensure right-hand-sides are always resolvable (ValueList and ExpressionList). Addressing all edge case with non-resolvable right-hand-sides would require a significant refactor and deprecation of some parts of the Lookup interface so this patch only focuses on FieldGetDbPrepValueIterableMixin (In and Range lookups) by making sure that a right-hand-side containing resolvables are dealt with appropriately during the resolving phase. Thanks Aashay Amballi for the report.
2025-01-20Fixed #36005 -- Dropped support for Python 3.10 and 3.11.Mariusz Felisiak
2025-01-15Refs #35405 -- Removed FieldCacheMixin.get_cache_name() per deprecation ↵Sarah Boyce
timeline.
2025-01-13Fixed #36086 -- Fixed crash when using GeneratedField with non-AutoField pk.Simon Charette
The previous logic was systematically attempting to retrieve last_insert_id even for models without an AutoField primary key when they had a GeneratedField on backends that can't return columns from INSERT. The issue affected MySQL, SQLite < 3.35, and Oracle when the use_returning_into option was disabled and could result in either crashes when the non-auto primary key wasn't an IntegerField subclass or silent misassignment of bogus insert ids (0 or the previous auto primary key insert value) to the first defined generated field value.
2024-12-09Fixed #35982 -- Made DecimalField.get_db_prep_value() call ↵Tim Graham
DatabaseOperations.adapt_decimalfield_value(). Regression in e9814029f570bd0866dc859147bca90340bcc913. Thanks Simon Charette for advice and review.
2024-12-04Fixed CVE-2024-53908 -- Prevented SQL injections in direct HasKeyLookup ↵Simon Charette
usage on Oracle. Thanks Seokchan Yoon for the report, and Mariusz Felisiak and Sarah Boyce for the reviews.
2024-12-03Refs #35842 -- Fixed handling of quotes in JSONField key lookups on Oracle.Sage Abdullah