Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#19688 closed Bug (fixed)

It's not possible to use `six.with_metaclass` to subclass `models.Model` with a custom metaclass.

Reported by: Simon Charette Owned by: Simon Charette
Component: Python 3 Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

A couple of django apps in the wild subclass models.base.BaseModel in order to provide some extra functionality.

If those apps are ever ported to support PY2 and PY3 in the same code base using six they will have to use six.with_metaclass to achieve it.

Unfortunately, models.base.BaseModel.__new__ chokes when a model is defined this way:

from django.db import models
from django.utils import six

class CustomBaseModel(models.base.BaseModel):
    pass

class CustomModel(six.with_metaclass(CustomBaseModel, models.Model)):
    pass

because the 'NewBase' checks don't take into account this case.

Attachments (1)

0001-Fixed-19688-Allow-model-subclassing-with-a-custom-me.patch (3.2 KB ) - added by Simon Charette 11 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Simon Charette, 11 years ago

Owner: changed from nobody to Simon Charette
Status: newassigned

comment:2 by Simon Charette, 11 years ago

Has patch: set

All tests pass on Python 2.7.3 SQLite.

comment:3 by Aymeric Augustin, 11 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Aymeric Augustin <aymeric.augustin@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 6b03179e126d4df01623dccc162c1579f349e41e:

Fixed #19688 -- Allow model subclassing with a custom metaclass using six.with_metaclass

comment:5 by Aymeric Augustin <aymeric.augustin@…>, 11 years ago

In f8b41da43156aa4283c83f2e579e8b18157c9b20:

[1.5.x] Fixed #19688 -- Allow model subclassing with a custom metaclass using six.with_metaclass

Backport of 6b03179e126d4df01623dccc162c1579f349e41e from master.

Although we're post RC 2, I'm backporting this because it's arguably a
major bug in a new feauture that will prevent several well-known
third-party apps from being ported to Python 3.

comment:6 by Aymeric Augustin <aymeric.augustin@…>, 11 years ago

In 7b49da1c3818cb90f95adaa0b18edaef5f088f16:

Changed testing strategy used in 6b03179e.

Avoid polluting the app cache as it causes unrelated test failures.

Refs #19688.

comment:7 by Aymeric Augustin <aymeric.augustin@…>, 11 years ago

In 455baa68ebabb472f901e3b476b3344c94090303:

[1.5.x] Changed testing strategy used in 6b03179e.

Avoid polluting the app cache as it causes unrelated test failures.

Refs #19688.

Backport of 7b49da1 from master.

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