MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_single_parent_backref

Method test_single_parent_backref

test/orm/test_cascade.py:2688–2723  ·  view source on GitHub ↗

test that setting m2m via a uselist=False backref bypasses the single_parent raise

(self)

Source from the content-addressed store, hash-verified

2686 assert_raises(sa_exc.InvalidRequestError, A, data="a2", bs=[b1])
2687
2688 def test_single_parent_backref(self):
2689 """test that setting m2m via a uselist=False backref bypasses the
2690 single_parent raise"""
2691
2692 a, A, B, b, atob = (
2693 self.tables.a,
2694 self.classes.A,
2695 self.classes.B,
2696 self.tables.b,
2697 self.tables.atob,
2698 )
2699
2700 self.mapper_registry.map_imperatively(
2701 A,
2702 a,
2703 properties={
2704 "bs": relationship(
2705 B,
2706 secondary=atob,
2707 cascade="all, delete-orphan",
2708 single_parent=True,
2709 backref=backref("a", uselist=False),
2710 )
2711 },
2712 )
2713 self.mapper_registry.map_imperatively(B, b)
2714
2715 b1 = B(data="b1")
2716 a1 = A(data="a1", bs=[b1])
2717
2718 assert_raises(sa_exc.InvalidRequestError, A, data="a2", bs=[b1])
2719
2720 a2 = A(data="a2")
2721 b1.a = a2
2722 assert b1 not in a1.bs
2723 assert b1 in a2.bs
2724
2725 def test_none_m2m_collection_assignment(self):
2726 a, A, B, b, atob = (

Callers

nothing calls this directly

Calls 6

relationshipFunction · 0.90
backrefFunction · 0.90
assert_raisesFunction · 0.90
map_imperativelyMethod · 0.80
BClass · 0.70
AClass · 0.70

Tested by

no test coverage detected