Code

Opened 2 years ago

Closed 23 months ago

#18343 closed Cleanup/optimization (fixed)

Refactor deferred model implementation

Reported by: akaariai 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

Description

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

  • in models/query_utils.py:
    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/base.py:
    1. Model.__reduce__ contained a dead variable, and stupid logic using that dead variable.
  • a minor cleanup to tests/modeltests/field_subclassing/tests.py to spot errors earlier if they happen

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

Attachments (0)

Change History (2)

comment:1 Changed 2 years ago by akaariai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

  • Resolution set to fixed
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.