From 78f7f6802175c6ef9a1c5160bbad0b9d2661f603 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Wed, 2 Aug 2017 18:16:36 +0500 Subject: [PATCH] Refs #28459 -- Improved performance of Model.from_db() when fields are deferred. --- django/db/models/base.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index 08394644469..da82a6446f8 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -489,9 +489,11 @@ class Model(metaclass=ModelBase): @classmethod def from_db(cls, db, field_names, values): if len(values) != len(cls._meta.concrete_fields): - values = list(values) - values.reverse() - values = [values.pop() if f.attname in field_names else DEFERRED for f in cls._meta.concrete_fields] + values_iter = iter(values) + values = [ + next(values_iter) if f.attname in field_names else DEFERRED + for f in cls._meta.concrete_fields + ] new = cls(*values) new._state.adding = False new._state.db = db