#29413: `QuerySet._extract_model_params` can/should be enchanced to support lazy
defaults
-------------------------------------+-------------------------------------
Reporter: Viktor Danyliuk | Owner: Liuyang
Type: | Qin
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: QuerySet | Triage Stage:
get_or_create update_or_create | Unreviewed
lazy |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Liuyang Qin):
This function takes function and any number of classes. If to simplify, it
returns wrapper(lets say "lazy function") instead of that function. At
that point we can say that we turned function into lazy function. After
that we can call this lazy function. Once called, it will return instance
of proxy class, without calling the initial function instead of result of
initial function. The initial function will be called only after we invoke
any method on that result(proxy instance). *resultclasses here is the
classes, instances of which are expected as results of the initial
function
I wish to have ability to write something like this:
{{{
from django.utils.functional import lazy
obj, created = model.objects.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 will be possible to call `_prepare_model_params` when
`model.DoesNotExist` or even inside `_create_object_from_params`.
--
Ticket URL: <https://code.djangoproject.com/ticket/29413#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.8679b99e2b791d06ad106ce8268a4bd7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.