-
-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Labels
awaiting author responseAwaiting response from issue openerAwaiting response from issue openerbugSomething isn't workingSomething isn't working
Description
I am running the mapper using async SQLAlchemy with a simple one-to-many relationship like the following.
# app.api.teams.models
class Team(Base):
__tablename__ = 'team'
id: Mapped[uuid.UUID] = mapped_column(types.UUID, primary_key=True, default=uuid.uuid4)
name: Mapped[str]
headquarters: Mapped[str]
# app.api.teams.graphql.types
@graphql_mapper.type(m.Team)
class Team:
pass
# app.api.heroes.models
class Hero(Base):
__tablename__ = 'hero'
id: Mapped[uuid.UUID] = mapped_column(types.UUID, primary_key=True, default=uuid.uuid4)
name: Mapped[str]
secret_name: Mapped[str]
age: Mapped[int]
team_id: Mapped[uuid.UUID] = mapped_column(types.UUID, ForeignKey('team.id'))
team: Mapped["Team"] = relationship()
# app.api.heroes.graphql.types
@graphql_mapper.type(m.Hero)
class Hero:
__exclude__ = ['secret_name']
This example works fine and I can access the Team
type through the Hero
type. The problem arises when I create the heroes
attribute on the Team
class (to make the relationship bi-lateral)
# app.api.teams.models
def resolve_hero():
from app.api.heroes.models import Hero
return Hero
class Team(Base):
__tablename__ = 'team'
id: Mapped[uuid.UUID] = mapped_column(types.UUID, primary_key=True, default=uuid.uuid4)
name: Mapped[str]
headquarters: Mapped[str]
heroes: Mapped[List["Hero"]] = relationship(resolve_hero, back_populates='team')
# app.api.heroes.models
class Hero(Base):
__tablename__ = 'hero'
id: Mapped[uuid.UUID] = mapped_column(types.UUID, primary_key=True, default=uuid.uuid4)
name: Mapped[str]
secret_name: Mapped[str]
age: Mapped[int]
team_id: Mapped[uuid.UUID] = mapped_column(types.UUID, ForeignKey('team.id'))
team: Mapped["Team"] = relationship("Team", back_populates='heroes')
At this moment, the app does not deploy and I get the following error message.
File "/app/app/api/heroes/graphql/types.py", line 13, in <module>
@graphql_mapper.type(m.Hero)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/strawberry_sqlalchemy_mapper/mapper.py", line 699, in convert
strawberry_type = self._convert_relationship_to_strawberry_type(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/strawberry_sqlalchemy_mapper/mapper.py", line 397, in _convert_relationship_to_strawberry_type
if self._get_relationship_is_optional(relationship):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/strawberry_sqlalchemy_mapper/mapper.py", line 406, in _get_relationship_is_optional
if relationship.direction in [ONETOMANY, MANYTOMANY]:
^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 1332, in __getattr__
return self._fallback_getattr(key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 1301, in _fallback_getattr
raise AttributeError(key)
AttributeError: direction
I am using strawberry v0.266.0 and strawberry-sqlalchemy-mapper v.0.6.0
david-1792
Metadata
Metadata
Assignees
Labels
awaiting author responseAwaiting response from issue openerAwaiting response from issue openerbugSomething isn't workingSomething isn't working