sqlalchemy-stubs icon indicating copy to clipboard operation
sqlalchemy-stubs copied to clipboard

Many to one relationship not recognised as list

Open maitham opened this issue 4 years ago • 3 comments

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")

maitham avatar Apr 28 '20 15:04 maitham

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.

3rdcycle avatar Apr 29 '20 15:04 3rdcycle

... 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.

ExplodingCabbage avatar Jun 22 '20 16:06 ExplodingCabbage

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.

lukaszdudek-codibly avatar Jun 25 '20 14:06 lukaszdudek-codibly