Opened 3 hours ago

Last modified 3 hours ago

#37259 assigned Bug

Model.from_db() overrides without fetch_mode argument crash with TypeError on any query

Reported by: Adam Johnson Owned by: Adam Johnson
Component: Database layer (models, ORM) Version: 6.1
Severity: Release blocker Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (1)

comment:1 by Adam Johnson, 3 hours ago

Has patch: set
Note: See TracTickets for help on using tickets.
Back to Top