#37259: Model.from_db() overrides without fetch_mode argument crash with TypeError
on any query
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: Adam Johnson
Johnson |
Type: Bug | Status: assigned
Component: Database | Version: 6.1
layer (models, ORM) |
Severity: Release | Keywords:
blocker |
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The fetch modes feature added in Django 6.1 (#28586) made every query
iteration path pass a new `fetch_mode` keyword argument to
`Model.from_db()`. Any model that overrides `from_db()` with the
signature documented in the model instance reference —
`from_db(cls, db, field_names, values)`, including the documented
`_loaded_values` example — now crashes on **any** database fetch:
{{{
TypeError: MyModel.from_db() got an unexpected keyword argument
'fetch_mode'
}}}
This worked on Django 6.0 and all earlier versions.
The proposed fix is to deprecate `from_db()` overrides that do not accept
the new `fetch_mode` keyword argument, using `django.utils.inspect` to
detect the override signature and conditionally pass `fetch_mode` or not,
emitting a `RemovedInDjango70Warning` for old-signature overrides.
--
Ticket URL: <
https://code.djangoproject.com/ticket/37259>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.