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

`backref` relationships raise `has no attribute`

Open ojomio opened this issue 4 years ago • 1 comments

For example, the following code fails to validate:

from sqlalchemy.orm import backref, relationship
from sqlalchemy.sql.schema import Column, ForeignKey
from sqlalchemy.sql.sqltypes import Integer
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()
class A(Base):
    id = Column(Integer, primary_key=True)


class B(Base):
    id = Column(Integer, primary_key=True)
    a_id = Column(
        Integer, ForeignKey('a.id', ondelete='CASCADE'), index=True, nullable=False
    )

    a = relationship(A, backref=backref('bs'))


print(B().a)
print(A().bs)

sql.py:24: error: "A" has no attribute "bs"
Found 1 error in 1 file (checked 1 source file)

ojomio avatar Jul 29 '20 11:07 ojomio

does anyone have a workaround for this?

zhammer avatar Jan 25 '21 20:01 zhammer