Opened 13 days ago

Last modified 10 days ago

#35976 closed New feature

Persist original Meta class on Options instances — at Version 3

Reported by: Tim McCurrach Owned by:
Component: Database layer (models, ORM) Version: 5.1
Severity: Normal Keywords:
Cc: Tim McCurrach, Simon Charette Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Tim McCurrach)

When a model.Model class is created the metaclass `pop`s off any Meta attribue defined on the model before calling super.__new__(). We do pass it as an argument to the Options class, and it's stored on the Options instance, however this is then deleted whilst the Options.contribute_to_class class is called. The attributes from the meta value are stored on a original_attrs attribute however. It might be a good idea to document this!!

Motivation for the documentation

The motivation for this came change is born out of a desire to write a check that db_table is explicitly defined on all my models (even if it matches the default value that django would apply). I can write checks that require things like ordering is defined (or not defined) on a model. The problem with db_table is that defaults are applied when contribute_to_class is called. This means we need a reference to the underlying original Meta data. The original_attrs attribute is perfect for this, but as far as I can tell it isn't documented anywhere.

Change History (3)

comment:1 by Sarah Boyce, 13 days ago

Cc: Simon Charette added
Resolution: wontfix
Status: newclosed

Hi Tim,

I was trying to understand if this was a new feature or a cleanup, but as you want a new attribute that you can rely on (and so would need to be documented), it makes sense that this is a new feature. Can you raise this on the Django Forum and see if others are in favor of the idea and if there are any concerns around doing this?

If the community agrees with the proposal, please return to this ticket and reference the forum discussion so we can re-open it.
For more information, please refer to the documented guidelines for requesting features.

comment:2 by Tim McCurrach, 12 days ago

Hi Sarah,

Thanks for the speedy reply. Yes, I wasn't sure if it was a new feature or clean-up either, but ended up thinking the same as you.

I started writing a post in the django forum, but as I was doing so, reading the code again I realised the feature I was asking for actually (more or less) already exists!! (https://github.com/django/django/blob/c075d4c2c8cef3c9b28180c749d421c63544a9dd/django/db/models/options.py#L189-L191 )

My only question now, is should we document this? I'll re-open the ticket as a documentation ticket and edit the description. If you think it's a good idea to document it, I'd be happy to add something.

(Should I still start a thread on the django-forum for this, as even though there are no code-changes I suppose this would be a new feature from an external perspective. Please do let me know. Thanks)

comment:3 by Tim McCurrach, 12 days ago

Component: Database layer (models, ORM)Documentation
Description: modified (diff)
Resolution: wontfix
Status: closednew
Type: New featureUncategorized
Note: See TracTickets for help on using tickets.
Back to Top