[Sqlalchemy-tickets] Issue #3847: declared_attr.cascading does not warn / error for non-mixin use (
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2016-11-08 01:41:00
|
New issue 3847: declared_attr.cascading does not warn / error for non-mixin use https://bitbucket.org/zzzeek/sqlalchemy/issues/3847/declared_attrcascading-does-not-warn-error Michael Bayer: use declared_attr.cascading on a non mixin, the "cascading" is ignored and it's only called once, totally confusing: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declared_attr Base = declarative_base() class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) @declared_attr.cascading def foo(cls): if cls.__name__ == 'A': return Column(String) else: return Column(Integer) class B(A): __tablename__ = 'b' id = Column(Integer, ForeignKey('a.id'), primary_key=True) e = create_engine("sqlite://", echo=True) Base.metadata.create_all(e) ``` output: ``` #!python CREATE TABLE a ( id INTEGER NOT NULL, foo VARCHAR, PRIMARY KEY (id) ) 2016-11-07 20:35:49,091 INFO sqlalchemy.engine.base.Engine () 2016-11-07 20:35:49,091 INFO sqlalchemy.engine.base.Engine COMMIT 2016-11-07 20:35:49,092 INFO sqlalchemy.engine.base.Engine CREATE TABLE b ( id INTEGER NOT NULL, PRIMARY KEY (id), FOREIGN KEY(id) REFERENCES a (id) ) ``` this should ideally either work or raise an error, though for now a warning is likely the best we can do. |