MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_single_parent_backref

Method test_single_parent_backref

test/orm/test_cascade.py:2689–2724  ·  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

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