support __table_args__ on single inh classes
Issue #2700
new
since we support columns on them too.
Workaround:
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import event
class FixTableArgs(object):
pass
@event.listens_for(FixTableArgs, "instrument_class", propagate=True)
def extra_table_args(mapper, cls):
if '__extra_table_args__' in cls.__dict__:
cls.__table__._init_items(*cls.__extra_table_args__)
del cls.__extra_table_args__
Base = declarative_base(cls=FixTableArgs)
class BaseClass(Base):
__tablename__ = "base"
id = Column(Integer, primary_key=True)
base_col = Column(Integer)
__table_args__ = (Index("ix1", base_col),)
class SubClass(BaseClass):
col_a = Column(Integer)
col_b = Column(Integer)
__extra_table_args__ = (UniqueConstraint("col_a", "col_b"), )
print BaseClass.__table__.constraints
Comments (6)
-
Account Deleted -
reporter see new event
-
reporter - changed milestone to 0.9.xx
-
reporter -
assigned issue to
- edited description
-
assigned issue to
-
reporter - changed milestone to 1.0.xx
-
reporter - changed milestone to 1.x.xx
- Log in to comment
The workaround works fine, thanks.
However, I noticed that the explicit
configure_mappers()
call is now required, otherwiseBase.metadata.create_all()
will miss constraints declared using this workaround. Actually, it's weirder than that, because I found a case when__extra_table_args__
was a tuple of aCHECK
and aUNIQUE
constraint, theCHECK
constraint was created, theUNIQUE
constraint was not. Callingconfigure_mappers()
beforeBase.metadata.create_all()
seems to sort things out. I've used 0.8.0 for testing.