Changes between Initial Version and Version 1 of Ticket #29413, comment 6
- Timestamp:
- May 21, 2018, 2:59:30 AM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #29413, comment 6
initial v1 1 The main issue is that defaultsare 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 defaultsare not needed (because [https://github.com/django/django/blob/master/django/db/models/query.py#L486 object exists]).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]). 3 3 4 4 5 5 Replying to [comment:5 Liuyang Qin]: 6 6 > 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 lazy10 >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`.