#34555: ModelBase metaclass implementation prevents addition of model fields via
__init_subclass__
-------------------------------------+-------------------------------------
Reporter: hottwaj | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: ModelBase | Triage Stage:
init_subclass | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* status: new => closed
* resolution: => wontfix
Comment:
Adapting `ModeBase.__new__` to play better with `__init_subclass__` and
possibly [https://code.djangoproject.com/ticket/24313 pave the way for
some deprecation] is one thing but maintaining backward compatibility (or
at least providing a bullet proof deprecation path) with the hundreds of
third-party applications that rely on the current implementation is-far
from trivial. For your particular use case to work, that is `cls._meta`
being already present at `__init_subclass__` time, the whole concept of
`add_to_class` would have to be thrown away as `object.__new__` (aka
`super().__new__` in `ModeBase.__new__`) triggers `__init_subclass__`.
That's also the reason why `contribute_to_class` is still relevant today
even if recent versions of Python introduced a `__set_name__` hook that is
a strong contender to replace it.
If you can demonstrate that there is a way to achieve such thing (e.g. a
PoC PR) and that there are strong enough benefits to warrant the burden
this will incur on third party application that have been using `__new__`
for years and might need to be adjusted then I believe you might have a
stronger case than by asking for this request to be adjusted in its
current form.
I'll be closing as ''wontfix'' until it can be demonstrated that this is
somewhat technically achievable at least.
--
Ticket URL: <https://code.djangoproject.com/ticket/34555#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070188083475d5-e14b0a4c-f8b5-4319-8bce-f0e10d59185c-000000%40eu-central-1.amazonses.com.