summaryrefslogtreecommitdiff
path: root/django/db/models/base.py
AgeCommit message (Collapse)Author
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.
2025-12-18Fixed #36701 -- Fixed memory leak in ModelState.Samriddha9619
2025-11-04Fixed #36704 -- Fixed system check error for proxy model with a composite pk.Hal Blackburn
Proxy models subclassing a model with a CompositePrimaryKey were incorrectly reporting check errors because the check that requires only local fields to be used in a composite pk was evaluated against the proxy subclass, which has no fields. To fix this, composite pk field checks are not evaluated against proxy subclasses, as none of the checks are applicable to proxy subclasses. This also has the benefit of not double-reporting real check errors from an invalid superclass pk. Thanks Clifford Gama for the review.
2025-10-18Fixed #21961 -- Added support for database-level delete options for ForeignKey.Mariusz Felisiak
Thanks Simon Charette for pair programming. Co-authored-by: Nick Stefan <NickStefan12@gmail.com> Co-authored-by: Akash Kumar Sen <71623442+Akash-Kumar-Sen@users.noreply.github.com> Co-authored-by: Simon Charette <charette.s@gmail.com>
2025-10-16Fixed #28586 -- Added model field fetch modes.Adam Johnson
May your database queries be much reduced with minimal effort. co-authored-by: Andreas Pelme <andreas@pelme.se> co-authored-by: Simon Charette <charette.s@gmail.com> co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
2025-10-14Fixed #36654 -- Corrected Model._do_update()'s docstring.Augusto Pontes
2025-10-13Fixed #36611, Refs #36580 -- Added system check for multicolumn ↵Sarah Boyce
ForeignObject in Meta.indexes/constraints/unique_together. ForeignObjects with multiple `from_fields` are not supported in these options. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com> Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
2025-09-17Refs #27222 -- Restored Model.save()'s refreshing of db_returning fields ↵Simon Charette
even if a value is set. The logic could likely be adjusted to assign the pre_save value in most cases to avoid the database transit but it could break in subtle ways so it's not worth the complexity it would require. Regression in 94680437a45a71c70ca8bd2e68b72aa1e2eff337. Co-authored-by: Tim Graham <timograham@gmail.com>
2025-09-16Refs #27222 -- Deduplicated db_returning fields in Model.save().Jacob Walls
Follow-up to 94680437a45a71c70ca8bd2e68b72aa1e2eff337.
2025-09-16Fixed #36580 -- Fixed constraint validation crash when condition uses a ↵SaJH
ForeignObject. Follow-up to e44e8327d3d88d86895735c0e427102063ff5b55. Refs #36222.
2025-09-14Fixed #27222 -- Refreshed model field values assigned expressions on save().Simon Charette
Removed the can_return_columns_from_insert skip gates on existing field_defaults tests to confirm the expected number of queries are performed and that returning field overrides are respected.
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-09-05Fixed #36564 -- Changed DEFAULT_AUTO_FIELD from AutoField to BigAutoField.Tim Graham
2025-07-23Refs #36500 -- Rewrapped long docstrings and block comments via a script.django-bot
Rewrapped long docstrings and block comments to 79 characters + newline using script from https://github.com/medmunds/autofix-w505.
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-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 #36273 -- Moved Index system checks from Model to Index.check().Tim Graham
2025-05-09Fixed #36207 -- Cleared cached ForeignObject relations via refresh_from_db().Jacob Walls
2025-05-08Fixed #36295, Refs #24305 -- Allowed overriding GenericForeignKey fields on ↵Ahmed Nassar
abstract models.
2025-03-31Refs #28909 -- Simplified code using unpacking generalizations.Aarni Koskela
2025-03-10Fixed #33579 -- Specialized exception raised on forced update failures.Simon Charette
Raising DatabaseError directly made it harder than it should to differentiate between IntegrityError when a forced update resulted in no affected rows. Introducing a specialized exception allows for callers to more easily silence, log, or turn them update failures into user facing exceptions (e.g. 404s). Thanks Mariusz for the review.
2025-02-19Fixed #35358, Refs #35234 -- Renamed _check() methods to check() for ↵Mariusz Felisiak
constraints.
2025-01-15Refs #35060 -- Removed passing positional arguments to Model.save()/asave() ↵Sarah Boyce
per deprecation timeline.
2025-01-15Fixed #36100 -- Checked if composite pk is set in get_next/get_previous.Jacob Walls
2025-01-14Refs #36075 -- Adjusted MTI handling of _non_pk_concrete_field_names.Simon Charette
Regression in bf7b17d16d3978b2e1cee4a0f7ce8840bd1a8dc4. Thanks Sage Abdullah for the report.
2025-01-14Fixed #36093 -- Adjusted unique checks to account for inherited primary keys.Simon Charette
Regression in bf7b17d16d3978b2e1cee4a0f7ce8840bd1a8dc4 refs #36075. Thanks Sage Abdullah for the report and tests.
2025-01-13Fixed #36092 -- Disallowed non-local fields in composite primary keys.Bendeguz Csirmaz
2025-01-13Refs #36075 -- Used field in pk_fields over field.primary_key.Sarah Boyce
2025-01-10Fixed #36064 -- Skipped an UPDATE when adding a model instance with a ↵Bendeguz Csirmaz
composite primary key with default values.
2025-01-10Refs #36064 -- Added Model.has_db_default() to encapsulate NOT_PROVIDED checks.Simon Charette
This avoids many awkward checks against NOT_PROVIDED and provides symmetry with Field.has_default() which is also the reason why it wasn't made a property.
2025-01-09Fixed #36074 -- Excluded composite primary key fields on save() updates.Simon Charette
2024-12-17Fixed #35992, Fixed #35997 -- Added system check for CompositePrimaryKeys in ↵Mariusz Felisiak
Meta.indexes/constraints/unique_together. CompositePrimaryKeys are not supported in any of these options.
2024-12-02Fixed #35950 -- Restored refreshing of relations when fields deferred.Adam Johnson
Thank you to Simon Charette and Sarah Boyce for the review. Regression in 73df8b54a2fab53bec4c7573cda5ad8c869c2fd8.
2024-11-29Fixed #373 -- Added CompositePrimaryKey.Bendeguz Csirmaz
Thanks Lily Foote and Simon Charette for reviews and mentoring this Google Summer of Code 2024 project. Co-authored-by: Simon Charette <charette.s@gmail.com> Co-authored-by: Lily Foote <code@lilyf.org>
2024-09-09Refs #373 -- Added Model._is_pk_set() abstraction to check if a Model's PK ↵Csirmaz Bendegúz
is set.
2024-08-28Refs #35060 -- Adjusted deprecation warning stacklevel in Model.save()/asave().Simon Charette
2024-08-12Fixed #35575 -- Added support for constraint validation on GeneratedFields.Mark Gensler
2024-08-05Refs #35638 -- Avoided wrapping expressions with Value in ↵David Sanders
_get_field_value_map() and renamed to _get_field_expression_map().
2024-07-04Fixed #35560 -- Made Model.full_clean() ignore GeneratedFields for constraints.Mark Gensler
Accessing generated field values on unsaved models caused a crash when validating CheckConstraints and UniqueConstraints with expressions.
2024-06-28Refs #35561 -- Renamed Model.save()/asave() helper to a more specific name.nessita
2024-06-26Fixed 35561 -- Made *args and **kwargs parsing more strict in ↵nessita
Model.save()/asave().
2024-06-25Fixed #35554, Refs #35060 -- Corrected deprecated *args parsing in ↵Adam Johnson
Model.save()/asave(). The transitional logic added to deprecate the usage of *args for Model.save()/asave() introduced two issues that this branch fixes: * Passing extra positional arguments no longer raised TypeError. * Passing a positional but empty update_fields would save all fields. Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
2024-05-07Fixed #35425 -- Avoided INSERT with force_update and explicit pk.Jacob Walls
Affected models where the primary key field is defined with a default or db_default, such as UUIDField.
2024-04-10Fixed #35350 -- Fixed save() with pk set on models with GeneratedFields.Sarah Boyce
Thanks Matt Hegarty for the report and Simon Charette and Natalia Bidart for the reviews. Regression in f333e35.
2024-03-08Fixed #35044 -- Avoided clearing reverse relations and private fields when ↵Giannis Terzopoulos
accessing deferred fields. Regression in a7b5ad8b19a08d7d57302ece74f6e26d2887fd9f for reverse relations and possibly in 123b1d3fcf79f091573c40be6da7113a6ef35b62 for private fields.
2024-03-08Optimized Model.refresh_from_db(fields=...) by using a set.Giannis Terzopoulos
2024-03-08Fixed #35223 -- Made Model.full_clean() ignore fields with db_default when ↵Ben Cail
validating empty values. Thanks Brian Ibbotson for the report. Regression in 7414704e88d73dafbcfbb85f9bc54cb6111439d3.
2024-02-29Refs #35234 -- Moved constraint system checks to Check/UniqueConstraint methods.Simon Charette
2024-02-26Fixed #35241 -- Cached model's full parent list.Adam Johnson
co-authored-by: Keryn Knight <keryn@kerynknight.com> co-authored-by: Natalia <124304+nessita@users.noreply.github.com> co-authored-by: David Smith <smithdc@gmail.com> co-authored-by: Paolo Melchiorre <paolo@melchiorre.org>
2024-02-20Fixed #35236 -- Used Field.attname/column attributes instead of ↵Adam Johnson
get_attname()/get_attname_column().