from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.orm import foreign, relationship
from sqlalchemy.sql.expression import and_
from app.models.translation.translation import Translation
class TranslatableMixin:
@declared_attr
def translations(cls):
return relationship(
Translation,
# FIX: Pyright type error
primaryjoin=and_(
foreign(Translation.translatable_id) == cls.id,
Translation.translatable_type == cls.__tablename__,
),
remote_side=[Translation.translatable_id],
viewonly=True,
)
def get_translation(self, field: str, language: str = "en"):
return next(
(
t.translation
for t in self.translations
if t.field_name == field and t.language.iso639 == language
),
None,
)
error: Cannot access member "id" for type "TranslatableMixin*"ย ย Member "id" is unknown 14:61:9 Pyright reportGeneralTypeIssues
Is there a way to fix this typing error?