Code

Opened 20 months ago

Last modified 4 weeks ago

#19396 new Cleanup/optimization

Allow customized ModelState classes

Reported by: akaariai Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

By allowing classes to define customized ModelState classes and by introducing some hooks into model saving custom Model subclasses can implement some often requested things:

  • Automatic primary key updates
  • Save only changed data
  • Proper optimistic locking

Two of the above ideas are implemented in the added tests in https://github.com/akaariai/django/compare/akaariai:model_save_refactor...akaariai:model_state_improvements. The patch is based on model_save_refactor from #16649.

The cost of this is a performance penalty of a 3-5% for instantiating single-field models from DB (query_all benchmark of djangobench), less for multi-field models.

I'd like to keep this private API for a while until more is known about what kinds of states are needed.

Attachments (0)

Change History (3)

comment:1 Changed 19 months ago by russellm

  • Triage Stage changed from Unreviewed to Design decision needed

Seems like a reasonable idea on the face of it, but needs some more discussion before we formally accept the idea.

comment:2 Changed 16 months ago by apollo13

  • Triage Stage changed from Design decision needed to Accepted

I think it would be great to have.

comment:3 Changed 4 weeks ago by timo

  • Patch needs improvement set

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


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

 
Note: See TracTickets for help on using tickets.