MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_no_delete_PK_AtoB

Method test_no_delete_PK_AtoB

test/orm/test_relationships.py:1648–1678  ·  view source on GitHub ↗

A can't be deleted without B because B would have no PK value.

(self)

Source from the content-addressed store, hash-verified

1646 sess.commit()
1647
1648 def test_no_delete_PK_AtoB(self):
1649 """A can't be deleted without B because B would have no PK value."""
1650
1651 tableB, A, B, tableA = (
1652 self.tables.tableB,
1653 self.classes.A,
1654 self.classes.B,
1655 self.tables.tableA,
1656 )
1657
1658 self.mapper_registry.map_imperatively(
1659 A,
1660 tableA,
1661 properties={"bs": relationship(B, cascade="save-update")},
1662 )
1663 self.mapper_registry.map_imperatively(B, tableB)
1664
1665 a1 = A()
1666 a1.bs.append(B())
1667 with fixture_session() as sess:
1668 sess.add(a1)
1669 sess.flush()
1670
1671 sess.delete(a1)
1672
1673 assert_raises_message(
1674 AssertionError,
1675 "Dependency rule on column 'tableA.id' tried to blank-out "
1676 "primary key column 'tableB.id' on instance ",
1677 sess.flush,
1678 )
1679
1680 def test_no_delete_PK_BtoA(self):
1681 tableB, A, B, tableA = (

Callers

nothing calls this directly

Calls 10

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
assert_raises_messageFunction · 0.90
map_imperativelyMethod · 0.80
AClass · 0.70
BClass · 0.70
appendMethod · 0.45
addMethod · 0.45
flushMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected