Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Also reported upstream to Djangohere.
The following code works on Python 3.12 and I believe#85160 is the cause.
When traversing a relationship and then calling asingledispatchmethod method registered on a model, the reference to self seems to get cached and locked to the first created model.
classTest(models.Model): ...classTest2(models.Model):relationship=models.ForeignKey("Test",on_delete=models.CASCADE)@singledispatchmethoddefbug(self,x):print(">",id(self))@bug.registerdef_(self,x:int):print(">",id(self))
and then it's pretty easy to trigger:
fortintest.test2_set.all():print("id:",id(t))# always changest.bug(4)# only ever prints a single id
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Linked PRs
- gh-127750: Improve caching in singledispatchmethod #127751
- gh-127750: Fix singledispatchmethod caching #127839
- gh-127750: Fix singledispatchmethod caching (v2) #128648
- gh-127750: Fix and optimize functools.singledispatchmethod() #130008
- [3.13] gh-127750: Fix functools.singledispatchmethod() #130029
- gh-127750: Improve repr of functools.singledispatchmethod #130220
- gh-127750: Restore inspect and pydoc support of singledispatchmethod #130309
- [3.13] gh-127750: Backport some tests for singledispatchmethod (GH-130309) #130340
- [3.12] gh-127750: Backport some tests for singledispatchmethod (GH-130309) (GH-130340) #130341