[Django] #19539: Writing custom model fields: The __metaclass__ attribute is no longer supported in Python 3

18 views
Skip to first unread message

Django

unread,
Dec 30, 2012, 9:21:36 AM12/30/12
to django-...@googlegroups.com
#19539: Writing custom model fields: The __metaclass__ attribute is no longer
supported in Python 3
-------------------------------+-------------------------
Reporter: astorije@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.5-alpha-1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-------------------------
As Django 1.5 introduces the support of Python 3, I think the
documentation of "Writing custom model fields" should warn developers
that:

{{{
#!python
class MyCustomField(models.Field):
__metaclass__ = models.SubfieldBase
}}}

is no longer supported and that they should use:

{{{
#!python
class MyCustomField(models.Field, metaclass=models.SubfieldBase):
...
}}}

instead.

Writing in the first (old) fashion results in no errors or warnings
whatsoever. The to_python() method is just not called as it should be...

--
Ticket URL: <https://code.djangoproject.com/ticket/19539>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 30, 2012, 11:28:14 AM12/30/12
to django-...@googlegroups.com
#19539: Writing custom model fields: The __metaclass__ attribute is no longer
supported in Python 3
-------------------------------+---------------------------------------

Reporter: astorije@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.5-alpha-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

The second version isn't acceptable as is because it's a syntax error
under Python 2. If you want a single snippet that works in Python 2 and 3
you have to use `six.with_metaclass`.

Currently the documentation assumes Python 2. We haven't chosen how to
document things that are different in Python 2 and 3 yet.

Technically, this ticket is valid, but it covers about 0.1% of the
problem. For starters, the docs has tons of `__unicode__` methods that
don't make any sense under Python 3...

--
Ticket URL: <https://code.djangoproject.com/ticket/19539#comment:1>

Django

unread,
Dec 31, 2012, 2:26:58 PM12/31/12
to django-...@googlegroups.com
#19539: Writing custom model fields: The __metaclass__ attribute is no longer
supported in Python 3
-------------------------------------+-------------------------------------
Reporter: astorije@… | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version:
Severity: Normal | 1.5-alpha-1
Keywords: | Resolution:
Has patch: 0 | Triage Stage: Design
Needs tests: 0 | decision needed
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* type: Uncategorized => New feature
* stage: Unreviewed => Design decision needed


--
Ticket URL: <https://code.djangoproject.com/ticket/19539#comment:2>

Django

unread,
Mar 22, 2013, 3:24:10 PM3/22/13
to django-...@googlegroups.com
#19539: Writing custom model fields: The __metaclass__ attribute is no longer
supported in Python 3
-------------------------------+---------------------------------------
Reporter: astorije@… | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 1.5-alpha-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by aaugustin):

* stage: Design decision needed => Accepted


Comment:

We'll have to fix this at some point.

--
Ticket URL: <https://code.djangoproject.com/ticket/19539#comment:3>

Django

unread,
Jul 4, 2013, 9:39:34 PM7/4/13
to django-...@googlegroups.com
#19539: Writing custom model fields: The __metaclass__ attribute is no longer
supported in Python 3
-------------------------------+---------------------------------------
Reporter: astorije@… | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 1.5-alpha-1

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by timo):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/19539#comment:4>

Django

unread,
Jul 5, 2013, 2:51:51 AM7/5/13
to django-...@googlegroups.com
#19539: Writing custom model fields: The __metaclass__ attribute is no longer
supported in Python 3
-------------------------------------+-------------------------------------
Reporter: astorije@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version:
Component: Documentation | 1.5-alpha-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* type: New feature => Cleanup/optimization
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/19539#comment:5>

Django

unread,
Jul 5, 2013, 6:54:36 AM7/5/13
to django-...@googlegroups.com
#19539: Writing custom model fields: The __metaclass__ attribute is no longer
supported in Python 3
-------------------------------------+-------------------------------------
Reporter: astorije@… | Owner: nobody
Type: | Status: closed

Cleanup/optimization | Version:
Component: Documentation | 1.5-alpha-1
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"b9fceadfd440daec09dee3c7c9d01997f94ec94f"]:
{{{
#!CommitTicketReference repository=""
revision="b9fceadfd440daec09dee3c7c9d01997f94ec94f"
Fixed #19539 -- Updated custom model fields example for Python 3.

Thanks astorije@ for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19539#comment:6>

Django

unread,
Jul 5, 2013, 6:55:08 AM7/5/13
to django-...@googlegroups.com
#19539: Writing custom model fields: The __metaclass__ attribute is no longer
supported in Python 3
-------------------------------------+-------------------------------------
Reporter: astorije@… | Owner: nobody

Type: | Status: closed
Cleanup/optimization | Version:
Component: Documentation | 1.5-alpha-1
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"6c984587711f82c0fc5223bbf6e8bb3b71732a3e"]:
{{{
#!CommitTicketReference repository=""
revision="6c984587711f82c0fc5223bbf6e8bb3b71732a3e"
[1.5.x] Fixed #19539 -- Updated custom model fields example for Python 3.

Thanks astorije@ for the report.

Backport of b9fceadfd4 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19539#comment:7>

Django

unread,
Jul 5, 2013, 6:55:09 AM7/5/13
to django-...@googlegroups.com
#19539: Writing custom model fields: The __metaclass__ attribute is no longer
supported in Python 3
-------------------------------------+-------------------------------------
Reporter: astorije@… | Owner: nobody

Type: | Status: closed
Cleanup/optimization | Version:
Component: Documentation | 1.5-alpha-1
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"14a5b79e294506ab045a14fbec89030510f1cefe"]:
{{{
#!CommitTicketReference repository=""
revision="14a5b79e294506ab045a14fbec89030510f1cefe"
[1.6.x] Fixed #19539 -- Updated custom model fields example for Python 3.

Thanks astorije@ for the report.

Backport of b9fceadfd4 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19539#comment:8>

Reply all
Reply to author
Forward
0 new messages