﻿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
36389	GenericRelation uses read connection for writes	Jake Howard	JaeHyuckSa	"When trying to modify a `GenericRelation` (the other side of a `GenericForeignKey`) in a multi-DB environment the read connection (""replica"") is used:

{{{#!python
instance.relation.db  # replica - CORRECT

instance.relation.update(field=""value"")  # also uses the replica - WRONG
}}}

This includes when explicitly requesting the ""default"" DB:

{{{#!python
instance = MyModel.objects.using(""default"").first()

instance.relation.update(field=""value"")  # also uses the replica - WRONG
}}}

In cases where the `db_for_read` is read-only (common in HA environments), this produces an error.

I've created a minimal reproduction with a failing test to demo: https://github.com/RealOrangeOne/django-generic-relation-db-repro. I've tested this against Django 4.2 - 5.2.

I did some digging, and it seems to be something around the `db` property. `Model.objects.update` seems to correctly switch to the write instance, but I can't quite see where. My guess is that the generic relation needs to do the same, but the inheritance and dynamic classes makes it hard to trace."	Bug	assigned	Database layer (models, ORM)	5.2	Normal				Accepted	1	0	0	1	0	0
