sqlalchemy-stubs
sqlalchemy-stubs copied to clipboard
Missing __iter__ for ORM relationship
With a class attribute such as:
foobaz = sqlalchemy.orm.relationship(
foobar,
back_populates="relationxyz",
cascade="all, delete, delete-orphan",
)
Iterating over the attributes raises:
[x for x in myinstance.foobaz]
error: "MyClass" has no attribute "__iter__" (not iterable)
It might need a workaround like: https://github.com/dropbox/sqlalchemy-stubs/commit/91e8ca9b369d8980459e5b673d40cae9d3d88b92
That might be more than that. You can easily get other warnings such as:
error: Argument 1 to "len" has incompatible type "MyClass"; expected "Sized"
error: Value of type "MyClass" is not indexable
etc.
It sounds like the relationship type is not considered as a list at all whereas it can act like one.
The plugin requires uselist=True
to be specified (probably for performance reasons).