{{{
from django.db import models
class PageBase(models.base.ModelBase):
def __init__(cls, name, bases, dct):
super(PageBase, cls).__init__(name, bases, dct)
if 'magic' in dct:
print("enabling magic on %s" % (name))
class Page(models.Model, metaclass=PageBase):
magic = True
title = models.CharField(max_length=255)
}}}
As of commit a68ea231012434b522ce45c513d84add516afa60, this fails because
all attributes without a `contribute_to_class` method are popped from the
dict in `ModelBase.__new__` .
(This pattern is used by Wagtail's Page model
https://github.com/wagtail/wagtail/blob/3e1e67021e0a20783ed59e17b43e3c481897fce3/wagtail/core/models.py#L190
, so this is causing various failures against django stable/2.2.x.)
--
Ticket URL: <https://code.djangoproject.com/ticket/30254>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Sergey Fedoseev (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/30254#comment:1>
* has_patch: 0 => 1
Comment:
PR: https://github.com/django/django/pull/11085
--
Ticket URL: <https://code.djangoproject.com/ticket/30254#comment:2>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/30254#comment:3>
* severity: Normal => Release blocker
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/30254#comment:4>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"985e6c224be0681d7a753b9ded4646024d332bc7" 985e6c22]:
{{{
#!CommitTicketReference repository=""
revision="985e6c224be0681d7a753b9ded4646024d332bc7"
[2.2.x] Fixed #30254 -- Allowed model metaclasses to access the attribute
dict in __init__().
Regression in a68ea231012434b522ce45c513d84add516afa60.
Backport of 58ad030d05fa50cfed327368ab61defca3303e02 from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30254#comment:5>
Comment (by Tim Graham <timograham@…>):
In [changeset:"58ad030d05fa50cfed327368ab61defca3303e02" 58ad030d]:
{{{
#!CommitTicketReference repository=""
revision="58ad030d05fa50cfed327368ab61defca3303e02"
Fixed #30254 -- Allowed model metaclasses to access the attribute dict in
__init__().
Regression in a68ea231012434b522ce45c513d84add516afa60.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30254#comment:6>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"607ff4efa31cd0c2217ed021dc939ffddad89c97" 607ff4e]:
{{{
#!CommitTicketReference repository=""
revision="607ff4efa31cd0c2217ed021dc939ffddad89c97"
Refs #30254 -- Added tests for Model.__hash__() inheritance.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30254#comment:7>