Opened 7 years ago

Closed 7 years ago

#18343 closed Cleanup/optimization (fixed)

Refactor deferred model implementation

Reported by: Anssi Kääriäinen Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


There are a couple of places in the deferred model implementation which needed cleanup.

  • in models/
    1. the attribute loaded is dead code.
    2. the weak_ref to model isn't needed.
    3. improve the handling of inheritance primary key cases (if parent_ptr_id is already fetched, then assessing pk should not generate any database queries, as parent_ptr_id already contains the value).
  • in models/
    1. Model.__reduce__ contained a dead variable, and stupid logic using that dead variable.
  • a minor cleanup to tests/modeltests/field_subclassing/ to spot errors earlier if they happen

The work is tracked in branch defer_inheritance_pk, I will create a pull request soon.

Change History (2)

comment:1 Changed 7 years ago by Anssi Kääriäinen

comment:2 Changed 7 years ago by Anssi Kääriäinen <akaariai@…>

Resolution: fixed
Status: newclosed

In [a8a81aae20a81e012fddc24f3ede556501af64a2]:

Fixed #18343 -- Cleaned up deferred model implementation

Generic cleanup and dead code removal in deferred model field loading
and model.reduce().

Also fixed an issue where if an inherited model with a parent field
chain parent_ptr_id -> id would be deferred loaded, then accessing
the id field caused caused a database query, even if the id field's
value is already loaded in the parent_ptr_id field.

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