Opened 7 years ago

Last modified 6 years ago

#29413 closed Cleanup/optimization

`QuerySet._extract_model_params` can/should be enchanced to support lazy defaults — at Initial Version

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

Description

I wish to have ability to write something like this:

from django.utils.functional import lazy

obj, created = model.objects.select_related('user').get_or_create(
     key=jwt,
     defaults=lazy(self.get_defaults_for_model, dict)(jwt) 
)

But at the moment _extract_model_params prepare defaults before it's realy needed.
I think _extract_model_params should be separated to _prepare_model_lookup and _prepare_model_params.
So it's will be possible to call _prepare_model_params when model.DoesNotExist or even inside _create_object_from_params.

Change History (0)

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