This test illustrates that with load=False, we can't just copy the committed_state of the merged instance over; since it references collection objects which themselves are to be merged. This committed_state would instead need to be piecemeal 'converted' to r
(self)
| 1150 | eq_(u.addresses[1].user, User(id=7, name="fred")) |
| 1151 | |
| 1152 | def test_dontload_with_eager(self): |
| 1153 | """ |
| 1154 | |
| 1155 | This test illustrates that with load=False, we can't just copy |
| 1156 | the committed_state of the merged instance over; since it |
| 1157 | references collection objects which themselves are to be merged. |
| 1158 | This committed_state would instead need to be piecemeal |
| 1159 | 'converted' to represent the correct objects. However, at the |
| 1160 | moment I'd rather not support this use case; if you are merging |
| 1161 | with load=False, you're typically dealing with caching and the |
| 1162 | merged objects shouldn't be 'dirty'. |
| 1163 | |
| 1164 | """ |
| 1165 | |
| 1166 | users, Address, addresses, User = ( |
| 1167 | self.tables.users, |
| 1168 | self.classes.Address, |
| 1169 | self.tables.addresses, |
| 1170 | self.classes.User, |
| 1171 | ) |
| 1172 | |
| 1173 | self.mapper_registry.map_imperatively( |
| 1174 | User, |
| 1175 | users, |
| 1176 | properties={ |
| 1177 | "addresses": relationship( |
| 1178 | self.mapper_registry.map_imperatively(Address, addresses) |
| 1179 | ) |
| 1180 | }, |
| 1181 | ) |
| 1182 | with fixture_session(expire_on_commit=False) as sess: |
| 1183 | u = User() |
| 1184 | u.id = 7 |
| 1185 | u.name = "fred" |
| 1186 | a1 = Address() |
| 1187 | a1.email_address = "foo@bar.com" |
| 1188 | u.addresses.append(a1) |
| 1189 | |
| 1190 | sess.add(u) |
| 1191 | sess.commit() |
| 1192 | |
| 1193 | sess2 = fixture_session() |
| 1194 | u2 = sess2.get(User, 7, options=[sa.orm.joinedload(User.addresses)]) |
| 1195 | |
| 1196 | sess3 = fixture_session() |
| 1197 | u3 = sess3.merge(u2, load=False) # noqa |
| 1198 | |
| 1199 | def go(): |
| 1200 | sess3.flush() |
| 1201 | |
| 1202 | self.assert_sql_count(testing.db, go, 0) |
| 1203 | |
| 1204 | def test_no_load_disallows_dirty(self): |
| 1205 | """load=False doesn't support 'dirty' objects right now |
nothing calls this directly
no test coverage detected