Changes between Initial Version and Version 1 of Ticket #29413, comment 6


Ignore:
Timestamp:
May 21, 2018, 2:59:30 AM (7 years ago)
Author:
Viktor Danyliuk

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29413, comment 6

    initial v1  
    1 The main issue is that defaults are processed before they are really needed.
    2 If we have big `defaults` it will take some time to [https://github.com/django/django/blob/master/django/db/models/query.py#L544 process it] even if defaults are not needed (because [https://github.com/django/django/blob/master/django/db/models/query.py#L486 object exists]).
     1The main issue is that `defaults` are processed before they are really needed.
     2If we have big `defaults` it will take some time to [https://github.com/django/django/blob/master/django/db/models/query.py#L544 process it] even if `defaults` are not needed (because [https://github.com/django/django/blob/master/django/db/models/query.py#L486 object exists]).
    33
    44
    55Replying to [comment:5 Liuyang Qin]:
    66> 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
    7 > I wish to have ability to write something like this:
    8 > {{{
    9 > from django.utils.functional import lazy
    10 >
    11 > obj, created = model.objects.get_or_create(
    12 >      key=jwt,
    13 >      defaults=lazy(self.get_defaults_for_model, dict)(jwt)
    14 > )
    15 > }}}
    16 > But at the moment `_extract_model_params` prepare defaults before it's realy needed.
    17 > I think `_extract_model_params` should be separated to `_prepare_model_lookup` and `_prepare_model_params`.
    18 > So it will be possible to call `_prepare_model_params` when `model.DoesNotExist` or even inside `_create_object_from_params`.
Back to Top