@@ -58,6 +58,35 @@ async def test_update_model_doesnt_update_other_models_from_same_repo(
5858 assert updated_model2 .name == "SomeoneElse"
5959
6060
61+ async def test_update_model_updates_models_retrieved_by_other_repos (
62+ repository_class , model_class , sa_manager
63+ ):
64+ repo = repository_class (sa_manager .get_bind ())
65+ repo2 = repository_class (sa_manager .get_bind ())
66+
67+ # Populate a database entry to be used for tests
68+ model1 = model_class (
69+ name = "Someone" ,
70+ )
71+ await repo .save (model1 )
72+ assert model1 .model_id is not None
73+
74+ # Retrieve the models
75+ new_model1 = await repo .get (model1 .model_id )
76+
77+ # Update the model with another repository instance
78+ new_model1 .name = "StillSomeoneElse"
79+ await repo2 .save (new_model1 )
80+
81+ # Check model1 has been updated
82+ updated_model1 = await repo2 .get (model1 .model_id )
83+ assert updated_model1 .name == "StillSomeoneElse"
84+
85+ # Check model1 has been updated
86+ updated_model1b = await repo .get (model1 .model_id )
87+ assert updated_model1b .name == "StillSomeoneElse"
88+
89+
6190@patch .object (AsyncSessionHandler , "commit" , return_value = None , new_callable = AsyncMock )
6291async def test_commit_triggers_once_per_operation_using_internal_uow (
6392 mocked_uow_commit : AsyncMock , repository_class , model_class , sa_manager
0 commit comments