Opened 2 years ago

Closed 2 years ago

Last modified 2 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: charettes Owned by: charettes
Component: Python 3 Version: master
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 charettes 2 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 2 years ago by charettes

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to charettes
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 2 years ago by charettes

  • Has patch set

All tests pass on Python 2.7.3 SQLite.

comment:3 Changed 2 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 2 years ago by Aymeric Augustin <aymeric.augustin@…>

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

In 6b03179e126d4df01623dccc162c1579f349e41e:

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

comment:5 Changed 2 years ago by Aymeric Augustin <aymeric.augustin@…>

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 Changed 2 years ago by Aymeric Augustin <aymeric.augustin@…>

In 7b49da1c3818cb90f95adaa0b18edaef5f088f16:

Changed testing strategy used in 6b03179e.

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

Refs #19688.

comment:7 Changed 2 years ago by Aymeric Augustin <aymeric.augustin@…>

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