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 19095 Dubious code in multiple_database tests Aymeric Augustin nobody "`QueryTestCase.test_o2o_cross_database_protection` contains code that seems invalid to me. In that test, `UserProfile` has a nullable one-to-one relation to `User`. An unsaved instance of `User` called `charlie` is created at line 655, and a profile is attached to this instance at line 664: `charlie.userprofile = bob_profile`. But after saving everything, that doesn't work as expected: the profile isn't linked to the user! This is easy to understand: this line basically performs `bob_profile.user_id = charlie.id` (and populates relation caches); but since `charlie` is unsaved, `charlie.id` is `None`, hence `bob_profile.used_id` remains `None`. I'm attaching a patch for this test case that reloads the objects and tests that `charlie.userprofile == bob_profile` ; with this patch, the test fails, proving my point. ---- In #18153, I tried to catch such programming errors by raising an exception. And that breaks that test. I think this code needs to fixed, while preserving as much of the testing behavior as possible." Bug closed Database layer (models, ORM) dev Normal fixed Unreviewed 0 0 0 0 0 0