sqlalchemy-stubs
sqlalchemy-stubs copied to clipboard
`backref` relationships raise `has no attribute`
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)
does anyone have a workaround for this?