remove same-named relationship warning
The warning below:
util.warn("Warning: relationship '%s' on mapper "
"'%s' supersedes the same relationship "
"on inherited mapper '%s'; this can "
"cause dependency issues during flush"
% (self.key, self.parent, inheriting))
dates back to 4f5aa12547264fb6a2e2f3af58d02ff09949d302 , in December of 2007 in version 0.4. the commit has no test nor refers to any bug report and appears to be theoretical; "added a warning when a relation() is added to an inheriting mapper that is present on a super-mapper; multiple DependencyProcessors are not expected during the flush process". This was years before the unit of work rewrite.
in modern day, a test illustrating this use case:
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")
class ASub(A):
__tablename__ = 'a_sub'
id = Column(Integer, ForeignKey('a.id'), primary_key=True)
bs = relationship("B")
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)
s = Session(e)
s.add_all([
A(bs=[B(), B(), B()]),
ASub(bs=[B(), B(), B()])
])
s.commit()
for a in s.query(A):
assert len(a.bs) == 3
putting a pdb.set_trace() into OneToManyDP we can see:
(Pdb) self
OneToManyDP(ASub.bs)
(Pdb) cont
> /home/classic/dev/sqlalchemy/lib/sqlalchemy/orm/dependency.py(450)presort_saves()
-> for state in states:
(Pdb) self
OneToManyDP(A.bs)
(Pdb)
which illustrates that we do in fact have multiple DependencyProcessor objects for the same-named relationship.
It's not clear if there are in fact other effects from having same-named relationships on inheritance, however propose we drop the warning. If this encourages this pattern, then we'd find out if there are in fact cases where this is a problem and we can test for them.
Comments (2)
-
reporter -
reporter - changed status to resolved
Remove same-named relationship warning
Removed a warning that dates back to 0.4 which emits when a same-named relationship is placed on two mappers that inherits via joined or single table inheritance. The warning does not apply to the current unit of work implementation.
Change-Id: If528ec3a2f4dc60712d9044fd1ec6c4dfbf0eadb Fixes:
#3749→ <<cset 8952a30f0a27>>
- Log in to comment
https://gerrit.sqlalchemy.org/155