MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_merge_persistent

Method test_merge_persistent

test/orm/test_dynamic.py:1529–1571  ·  view source on GitHub ↗
(self, merge_type, user_address_fixture)

Source from the content-addressed store, hash-verified

1527 "empty", "persistent", "transient", argnames="merge_type"
1528 )
1529 def test_merge_persistent(self, merge_type, user_address_fixture):
1530 addresses = self.tables.addresses
1531 User, Address = user_address_fixture(
1532 addresses_args={"order_by": addresses.c.email_address}
1533 )
1534 sess = fixture_session(autoflush=False)
1535
1536 a1 = Address(email_address="a1")
1537 a2 = Address(email_address="a2")
1538 a3 = Address(email_address="a3")
1539 u1 = User(name="jack", addresses=[a2, a3])
1540
1541 if merge_type == "transient":
1542 # merge transient. no collection iteration is implied by this.
1543 u1 = sess.merge(u1)
1544 sess.add(a1)
1545 else:
1546 sess.add_all([u1, a1])
1547 sess.flush()
1548
1549 if merge_type == "persistent":
1550 u1 = User(id=u1.id, name="jane", addresses=[a1, a3])
1551
1552 # merge of populated list into persistent not supported with
1553 # write_only because we would need to iterate the existing list
1554 with self._expect_no_iteration():
1555 u1 = sess.merge(u1)
1556
1557 elif merge_type == "empty":
1558 # merge while omitting the "too large to load" collection
1559 # works fine.
1560 u1 = User(id=u1.id, name="jane")
1561 u1 = sess.merge(u1)
1562
1563 eq_(
1564 attributes.get_history(
1565 u1, "addresses", PassiveFlag.PASSIVE_NO_FETCH
1566 ),
1567 ([], [], []),
1568 )
1569
1570 sess.flush()
1571 eq_(sess.scalars(u1.addresses.select()).all(), [a2, a3])
1572
1573 def test_passive_deletes_required(self, user_address_fixture):
1574 addresses = self.tables.addresses

Callers

nothing calls this directly

Calls 13

fixture_sessionFunction · 0.90
eq_Function · 0.90
_expect_no_iterationMethod · 0.80
AddressClass · 0.70
UserClass · 0.70
mergeMethod · 0.45
addMethod · 0.45
add_allMethod · 0.45
flushMethod · 0.45
get_historyMethod · 0.45
allMethod · 0.45
scalarsMethod · 0.45

Tested by

no test coverage detected