﻿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
32965	Django related manager allways choose db_for_read router and fail update/delete	Regressor	nobody	"We have a large project running django 3.1.12. It is use aws aurora rds cluster for database and we tried to take most of it. Wee need to use read replicas to be able fast db overload response. So we made routers, started multiple db config, fixed number read replica lag issues and finally got error ""cannot execute DELETE in a read-only transaction"" in simple field .delete()

So. Example: We have a model with a generic relation:
    mentor_binds = GenericRelation('MentorBind', object_id_field='parent_object_id', content_type_field='parent_content_type')

And an exception when trying to clean binds:
   instance.mentor_binds.all().delete()

The only workaround is to add .using('default') before .delete() / .update()

I beelive this is a bug in GenericRelatedManager's  _apply_rel_filters() method. There is a string in it:

   db = self._db or router.db_for_read(self.model, instance=self.instance)

But I can't say this is the only place with such problem, so I had to add .using('default') before all .update() and .delete() - ~400 changes
"	Bug	closed	Database layer (models, ORM)	3.1	Normal	invalid	related manager, db_for_read, exception, db, router		Unreviewed	0	0	0	0	0	0
