﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35984	functools.singledispatchmethod on Django models don't work	Simon Gomizelj		"I'm on Django 4.2.17 and Python 3.13.1

The following code works on Python 3.12 and I believe https://github.com/python/cpython/issues/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.

{{{#!python
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:
{{{#!python
for t in test.test2_set.all():
    print(""id:"", id(t))  # always changes
    t.bug(4)             # only ever prints a single id
}}}"	Bug	closed	Database layer (models, ORM)	4.2	Normal	needsinfo			Unreviewed	0	0	0	0	0	0
