Opened 6 years ago

Last modified 3 months ago

#11078 new Cleanup/optimization

Proxy models do not inherit META.app_label

Reported by: gsong Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: proxy model app_label
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

According to the proxy model documentation:
"Proxy models inherit any Meta options that they don't define from their non-abstract model parent (the model they are proxying for)."

In the case of app_label, this is not true.

from django.db import models

class Book(models.Model):
    name = models.CharField(max_length=50)

    class Meta:
        app_label = 'core'

class Book1(Book):
    class Meta:
        proxy = True

>>> from django.db import models
>>> for model in models.get_models(): print model._meta
...
core.book
proxy.book1

Change History (13)

comment:1 Changed 6 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:3 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 11 months ago by aaugustin

This still happens after the app-loading refactor.

I couldn't locate the code that copies the original model's meta attributes to the proxy's meta. It looks like it could be Options.setup_proxy but that method only deals with a few attributes.

comment:6 Changed 3 months ago by marco-santamaria

Only the 'ordering' and 'get_latest_by' meta attributes get copied in the new method of ModelBase.

Therefore, if a meta attribute is not in ['ordering', 'get_latest_by'], it will not be inherited by the Meta class in the proxy model.

A pull request that removes that statement from the documentation has been proposed. See https://github.com/django/django/pull/4531

comment:7 Changed 3 months ago by marco-santamaria

  • Has patch set
  • Type changed from Bug to Cleanup/optimization

comment:8 Changed 3 months ago by Marco Santamaria <marco.santamaria@…>

  • Resolution set to fixed
  • Status changed from new to closed

In bae72bd:

Fixed #11078 -- documentation update.

comment:9 Changed 3 months ago by Florian Apolloner <apollo13@…>

In cc493d3c:

Merge pull request #4531 from marco-santamaria/ticket11078

Fixed #11078 -- documentation update.

comment:10 Changed 3 months ago by Tim Graham <timograham@…>

In 1e0bf2c:

[1.8.x] Fixed #11078 -- Removed inaccurate docs about proxy models Meta.

Backport of bae72bdd2aa93472617ed28fc3d5a01f0920ea6e from master

comment:11 Changed 3 months ago by Tim Graham <timograham@…>

In 276f760:

[1.7.x] Fixed #11078 -- Removed inaccurate docs about proxy models Meta.

Backport of bae72bdd2aa93472617ed28fc3d5a01f0920ea6e from master

comment:12 Changed 3 months ago by tyrion

I don't think we fixed this correctly. The doc was indeed wrong about inheriting "any Meta options", but the 'ordering' and 'get_latest_by' meta attributes are still copied to the new model.

This is why I think this behaviour should be either documented or removed.

comment:13 Changed 3 months ago by timgraham

  • Has patch unset
  • Resolution fixed deleted
  • Status changed from closed to new

Agreed.

Note: See TracTickets for help on using tickets.
Back to Top