Bug report
Bug description:
Also reported upstream to Django here.
The following code works on Python 3.12 and I believe #85160 is the cause.
When traversing a relationship and then calling a singledispatchmethod method registered on a model, the reference to self seems to get cached and locked to the first created model.
class Test(models.Model):
...
class Test2(models.Model):
relationship = models.ForeignKey("Test", on_delete=models.CASCADE)
@singledispatchmethod
def bug(self, x):
print(">", id(self))
@bug.register
def _(self, x: int):
print(">", id(self))
and then it's pretty easy to trigger:
for t in test.test2_set.all():
print("id:", id(t)) # always changes
t.bug(4) # only ever prints a single id
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Linked PRs
Bug report
Bug description:
Also reported upstream to Django here.
The following code works on Python 3.12 and I believe #85160 is the cause.
When traversing a relationship and then calling a
singledispatchmethodmethod registered on a model, the reference to self seems to get cached and locked to the first created model.and then it's pretty easy to trigger:
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Linked PRs