diff options
| author | Matt Westcott <matt@west.co.tt> | 2019-03-14 18:23:50 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2019-03-14 21:05:23 -0400 |
| commit | 58ad030d05fa50cfed327368ab61defca3303e02 (patch) | |
| tree | 4f378393844f8d2d41909fac3a1676f1040e2bff /django/db | |
| parent | f976ab1b117574db78d884c94e549a6b8e4c9f9b (diff) | |
Fixed #30254 -- Allowed model metaclasses to access the attribute dict in __init__().
Regression in a68ea231012434b522ce45c513d84add516afa60.
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/base.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index 2884679ba1..1ee97eb128 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -84,9 +84,12 @@ class ModelBase(type): # Pass all attrs without a (Django-specific) contribute_to_class() # method to type.__new__() so that they're properly initialized # (i.e. __set_name__()). + contributable_attrs = {} for obj_name, obj in list(attrs.items()): - if not _has_contribute_to_class(obj): - new_attrs[obj_name] = attrs.pop(obj_name) + if _has_contribute_to_class(obj): + contributable_attrs[obj_name] = obj + else: + new_attrs[obj_name] = obj new_class = super_new(cls, name, bases, new_attrs, **kwargs) abstract = getattr(attr_meta, 'abstract', False) @@ -146,8 +149,9 @@ class ModelBase(type): if is_proxy and base_meta and base_meta.swapped: raise TypeError("%s cannot proxy the swapped model '%s'." % (name, base_meta.swapped)) - # Add all attributes to the class. - for obj_name, obj in attrs.items(): + # Add remaining attributes (those with a contribute_to_class() method) + # to the class. + for obj_name, obj in contributable_attrs.items(): new_class.add_to_class(obj_name, obj) # All the fields of any type declared on this model |
