#35827: Model subclass with __init_subclass__ doesn't get correct _meta instance
-----------------------------+-----------------------------------------
     Reporter:  Ben Beecher  |                     Type:  Uncategorized
       Status:  new          |                Component:  Uncategorized
      Version:  5.0          |                 Severity:  Normal
     Keywords:               |             Triage Stage:  Unreviewed
    Has patch:  0            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  0
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+-----------------------------------------
 When defining and using a model mixin like so:

 ```
 class ModelMixin(Model):

     class Meta:
         abstract = True

     def __init_subclass__(cls) -> None:
         super().__init_subclass__()
         breakpoint()
         cls._my_setup_func()

 class TestModel(ModelMixin):
     name = models.CharField(max_length=100)
 ```

 The __init_subclass__ call will be first called when the class is created
 here:
 https://github.com/django/django/blob/main/django/db/models/base.py#L120

 However the meta is attached here:
 https://github.com/django/django/blob/main/django/db/models/base.py#L143

 So during the __init_subclass call you will have the superclass' meta
 object if you try to access it.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35827>
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/0107019272cffff5-3ac201ab-816f-449e-b9bc-99b32488936d-000000%40eu-central-1.amazonses.com.

Reply via email to