Opened 6 years ago

Closed 6 years ago

#29970 closed Bug (fixed)

Using cached_property on a model fails with: "Cannot use cached_property instance without calling __set_name__() on it."

Reported by: Collin Anderson Owned by: Sergey Fedoseev
Component: Utilities Version: dev
Severity: Release blocker Keywords:
Cc: cmawebsite@…, Sergey Fedoseev, Thomas Grainger, Matt Westcott Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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?

Change History (6)

comment:1 by Tim Graham, 6 years ago

Cc: Sergey Fedoseev Thomas Grainger added
Severity: NormalRelease blocker
Summary: Cannot use cached_property instance without calling __set_name__() on it.Using cached_property on a model fails with: "Cannot use cached_property instance without calling __set_name__() on it."
Triage Stage: UnreviewedAccepted

comment:2 by Sergey Fedoseev, 6 years ago

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:3 by Carlton Gibson, 6 years ago

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

comment:4 by Matt Westcott, 6 years ago

Cc: Matt Westcott added

comment:5 by Sergey Fedoseev, 6 years ago

Has patch: set

comment:6 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In a68ea23:

Fixed #29970, #30041 -- Made ModelBase.new() pass attrs without contribute_to_class() to type.new().

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