sqlalchemy-stubs
sqlalchemy-stubs copied to clipboard
Many to one relationship not recognised as list
The accounts object is not recognised as a list, when it is a many to one relationship. Am I doing something wrong here?
if TYPE_CHECKING:
from .account import Account # noqa: F401
class User(Base):
id = Column(Integer, primary_key=True, index=True)
accounts = relationship("Account", cascade="all,delete", backref="user")
Having run into this issue myself and looking at the code in sqlmypy.py
it seems that you need to add an explicit uselist=True
for it to work, even though this is the default value.
... and even then sqlmypy seems to only treat the relationship as an Iterable
rather than a List
, meaning it wrongly thinks you can't do things like do an index lookup on the relationship or append to it.
It seems that the only change to be made here is here: https://github.com/dropbox/sqlalchemy-stubs/blob/ea93332454f3d5646b87395f82b4d7badbd64de1/sqlmypy.py#L402 and some tests as well.