Diagrams can't recognize Sqlalchemy model dependencies across modules?

I have a bunch of SQLAlchemy models spread across different modules in a package. When I open a model dependency diagram for the package, Pycharm correctly recognizes the relationships between models in the same file, but not ones in different files.

Is there some way I can nudge Pycharm into recognizing the relationships? Is this a bug? (Or perhaps I'm the bug - maybe there's a good reason to keep all models together...?)

Here's a simple example. As written, Pycharm correctly observes the link between Spam and Eggs. But if you move the Eggs class to another module, Pycharm fails to observe the link.

from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship

from sqlalchemy import create_engine

Base = declarative_base()

class Spam(Base):

    __tablename__ = "spams"

    id = Column(Integer, primary_key=True)

class Eggs(Base):

    __tablename__ = "eggs"

    id = Column(Integer, primary_key=True)
    spamid = Column(Integer, ForeignKey("spams.id"))

    spam = relationship("Spam")

if __name__ == '__main__':
    engine = create_engine("sqlite:///spam.db")
    Session = sessionmaker(engine)
    s = Session()
Comment actions Permalink
Hi Colin,

it looks like a bug there. Please, file an issue in our tracker – http://youtrack.jetbrains.com/issues/PY
Comment actions Permalink

Is there any update on this?
I'm experiencing the same problem with PyCharm Professional 2016.1.2.


Please sign in to leave a comment.