[Django] #29970: Cannot use cached_property instance without calling __set_name__() on it.

280 views
Skip to first unread message

Django

unread,
Nov 20, 2018, 11:55:22 AM11/20/18
to django-...@googlegroups.com
#29970: Cannot use cached_property instance without calling __set_name__() on it.
-------------------------------------------+------------------------
Reporter: Collin Anderson | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
With Python 3.6.7 (on Ubuntu 18.04), I'm getting this error for a fairly
standard use of `cached_property`:

`TypeError: Cannot use cached_property instance without calling
__set_name__() on it.`

{{{
class MyModel(models.Model):
@cached_property
def my_method(self):
return 'test'
}}}

I assume this was broken by #29478. Maybe Django's custom `__new__` code
for models breaks the `__set_name__` hook?

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

Django

unread,
Nov 20, 2018, 5:16:21 PM11/20/18
to django-...@googlegroups.com
#29970: Using cached_property on a model fails with: "Cannot use cached_property

instance without calling __set_name__() on it."
---------------------------------+------------------------------------

Reporter: Collin Anderson | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: master
Severity: Release blocker | 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 Tim Graham):

* cc: Sergey Fedoseev, Thomas Grainger (added)
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


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

Django

unread,
Nov 20, 2018, 11:04:28 PM11/20/18
to django-...@googlegroups.com
#29970: Using cached_property on a model fails with: "Cannot use cached_property

instance without calling __set_name__() on it."
-------------------------------------+-------------------------------------
Reporter: Collin Anderson | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned
Component: Utilities | Version: master

Severity: Release blocker | 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 Sergey Fedoseev):

* status: new => assigned
* owner: nobody => Sergey Fedoseev


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

Django

unread,
Dec 3, 2018, 3:03:22 AM12/3/18
to django-...@googlegroups.com
#29970: Using cached_property on a model fails with: "Cannot use cached_property

instance without calling __set_name__() on it."
-------------------------------------+-------------------------------------
Reporter: Collin Anderson | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned
Component: Utilities | Version: master

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

Just noting, this is a Release Blocker for 2.2 (first release including
06076999026091cf007d8ea69146340a361259f8, fix from #29478).

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

Django

unread,
Dec 7, 2018, 7:18:35 AM12/7/18
to django-...@googlegroups.com
#29970: Using cached_property on a model fails with: "Cannot use cached_property

instance without calling __set_name__() on it."
-------------------------------------+-------------------------------------
Reporter: Collin Anderson | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned
Component: Utilities | Version: master

Severity: Release blocker | 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 Matt Westcott):

* cc: Matt Westcott (added)


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

Django

unread,
Dec 18, 2018, 3:34:23 AM12/18/18
to django-...@googlegroups.com
#29970: Using cached_property on a model fails with: "Cannot use cached_property

instance without calling __set_name__() on it."
-------------------------------------+-------------------------------------
Reporter: Collin Anderson | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned
Component: Utilities | Version: master

Severity: Release blocker | 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 Sergey Fedoseev):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/10763 PR]

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

Django

unread,
Dec 22, 2018, 6:11:49 PM12/22/18
to django-...@googlegroups.com
#29970: Using cached_property on a model fails with: "Cannot use cached_property

instance without calling __set_name__() on it."
-------------------------------------+-------------------------------------
Reporter: Collin Anderson | Owner: Sergey
| Fedoseev
Type: Bug | Status: closed
Component: Utilities | Version: master
Severity: Release blocker | Resolution: fixed
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 Tim Graham <timograham@…>):

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


Comment:

In [changeset:"a68ea231012434b522ce45c513d84add516afa60" a68ea23]:
{{{
#!CommitTicketReference repository=""
revision="a68ea231012434b522ce45c513d84add516afa60"
Fixed #29970, #30041 -- Made ModelBase.__new__() pass attrs without
contribute_to_class() to type.__new__().
}}}

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

Reply all
Reply to author
Forward
0 new messages