How do I split an SQLAlchemy Declarative model into modules?
How do I split an SQLAlchemy Declarative model into modules? I need to define multiple modules that contain SQLAlchemy Declarative classes. I've written a function in each module called subclass_base() into which a Base instance of declarative_base() is passed after instantiation. The first module's subclass_base() call correctly subclasses the Base instance and the subclasses are visible from outside the function. The second module's call finishes without errors but from both within the function and outside of it all of the subclasses are reflected in Base.__subclasses__ only some of the time. Here is a minimal working example with only 1 class definition in each module: subclass_base() declarative_base() subclass_base() Base.__subclasses__ modela.py from sqlalchemy import Column, Integer, String def subclass_base(Base): class Roles(Base): __tablename__ = 'roles' id = Column(Integer, primary_key=True) name = Column(String(32)) modelb...