[Sqlalchemy-tickets] Issue #3532: detect property being assigned to more than one parent, being ass
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2015-09-16 22:55:31
|
New issue 3532: detect property being assigned to more than one parent, being assigned twice https://bitbucket.org/zzzeek/sqlalchemy/issues/3532/detect-property-being-assigned-to-more Mike Bayer: e.g.: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) bs = relationship("B") b_1 = bs class B(Base): __tablename__ = 'b' id = Column(Integer, primary_key=True) a_id = Column(ForeignKey('a.id')) e = create_engine("sqlite://", echo=True) Base.metadata.create_all(e) configure_mappers() print A.bs.impl print A.b_1.impl ``` the basic idea, but this should be at most a warning in 1.0, error in 1.1: ``` #!diff diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index cd4a011..19f4e0f 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -147,6 +147,8 @@ class MapperProperty(_MappedAttribute, InspectionAttr, util.MemoizedSlots): setup when the mapper is first known. """ + if getattr(self, "parent", None) is not None: + raise Exception("oof") self.parent = parent def instrument_class(self, mapper): ``` needs: 1. tests 2. nice message 3. appropriate exception class 4. for 1.0 backport a warning 5. migration notes 6. changelog |