﻿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
31759	Why do instance hints in ForwardManyToOneDescriptor use the related object?	Daniel Miller	nobody	"Why do the `instance` hints in `ForwardManyToOneDescriptor` use the related object rather than the instance of the class being routed?

[https://github.com/django/django/blob/d36413a2eb5678dda35559a48769703acd784898/django/db/models/fields/related_descriptors.py#L223-L226 django/db/models/fields/related_descriptors.py:223]
{{{
if instance._state.db is None:
    instance._state.db = router.db_for_write(instance.__class__, instance=value)
if value._state.db is None:
    value._state.db = router.db_for_write(value.__class__, instance=instance)
}}}

I would expect that to read like so
{{{
if instance._state.db is None:
    instance._state.db = router.db_for_write(instance.__class__, instance=instance)
if value._state.db is None:
    value._state.db = router.db_for_write(value.__class__, instance=value)
}}}

It looks like it may be a historical artifact from [https://github.com/django/django/blob/acc095c333213eb1d978866ae5852cefe00ce4ef/django/db/models/fields/related.py#L285-L288 long ago], which was [https://github.com/django/django/commit/1b3dc8ad9a28486542f766ff93318aa6b4f5999b later converted] to what we see today.

The [https://docs.djangoproject.com/en/3.0/topics/db/multi-db/#topics-db-multi-db-hints documentation on multi-db hints] is vague, it says the instance is ""an object instance that is related to the read or write operation that is underway."" While this is technically not inaccurate, it seems non-intuitive to pass a related object rather than the object being routed."	Uncategorized	closed	Database layer (models, ORM)	3.0	Normal	invalid			Unreviewed	0	0	0	0	0	0
