mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #26207 -- Replaced dynamic classes with non-data descriptors for deferred instance loading.
This commit is contained in:
parent
dac075e910
commit
7f51876f99
17 changed files with 104 additions and 240 deletions
|
@ -19,7 +19,7 @@ from django.db.models.deletion import Collector
|
|||
from django.db.models.expressions import Date, DateTime, F
|
||||
from django.db.models.fields import AutoField
|
||||
from django.db.models.query_utils import (
|
||||
InvalidQuery, Q, check_rel_lookup_compatibility, deferred_class_factory,
|
||||
InvalidQuery, Q, check_rel_lookup_compatibility,
|
||||
)
|
||||
from django.db.models.sql.constants import CURSOR
|
||||
from django.utils import six, timezone
|
||||
|
@ -60,11 +60,6 @@ class ModelIterable(BaseIterable):
|
|||
model_fields_start, model_fields_end = select_fields[0], select_fields[-1] + 1
|
||||
init_list = [f[0].target.attname
|
||||
for f in select[model_fields_start:model_fields_end]]
|
||||
if len(init_list) != len(model_cls._meta.concrete_fields):
|
||||
init_set = set(init_list)
|
||||
skip = [f.attname for f in model_cls._meta.concrete_fields
|
||||
if f.attname not in init_set]
|
||||
model_cls = deferred_class_factory(model_cls, skip)
|
||||
related_populators = get_related_populators(klass_info, select, db)
|
||||
for row in compiler.results_iter(results):
|
||||
obj = model_cls.from_db(db, init_list, row[model_fields_start:model_fields_end])
|
||||
|
@ -1254,9 +1249,7 @@ class RawQuerySet(object):
|
|||
if skip:
|
||||
if self.model._meta.pk.attname in skip:
|
||||
raise InvalidQuery('Raw query must include the primary key')
|
||||
model_cls = deferred_class_factory(self.model, skip)
|
||||
else:
|
||||
model_cls = self.model
|
||||
model_cls = self.model
|
||||
fields = [self.model_fields.get(c) for c in self.columns]
|
||||
converters = compiler.get_converters([
|
||||
f.get_col(f.model._meta.db_table) if f else None for f in fields
|
||||
|
@ -1718,7 +1711,7 @@ class RelatedPopulator(object):
|
|||
return [row[row_pos] for row_pos in pos_list]
|
||||
self.reorder_for_init = reorder_for_init
|
||||
|
||||
self.model_cls = self.get_deferred_cls(klass_info, self.init_list)
|
||||
self.model_cls = klass_info['model']
|
||||
self.pk_idx = self.init_list.index(self.model_cls._meta.pk.attname)
|
||||
self.related_populators = get_related_populators(klass_info, select, self.db)
|
||||
field = klass_info['field']
|
||||
|
@ -1732,17 +1725,6 @@ class RelatedPopulator(object):
|
|||
if field.unique:
|
||||
self.reverse_cache_name = field.remote_field.get_cache_name()
|
||||
|
||||
def get_deferred_cls(self, klass_info, init_list):
|
||||
model_cls = klass_info['model']
|
||||
if len(init_list) != len(model_cls._meta.concrete_fields):
|
||||
init_set = set(init_list)
|
||||
skip = [
|
||||
f.attname for f in model_cls._meta.concrete_fields
|
||||
if f.attname not in init_set
|
||||
]
|
||||
model_cls = deferred_class_factory(model_cls, skip)
|
||||
return model_cls
|
||||
|
||||
def populate(self, row, from_obj):
|
||||
if self.reorder_for_init:
|
||||
obj_data = self.reorder_for_init(row)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue