Skip to content

Commit fe8bf1f

Browse files
committed
fix some mypy
1 parent 0182a82 commit fe8bf1f

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/strawberry_sqlalchemy_mapper/loader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ async def load_fn(keys: List[Tuple]) -> List[Any]:
7777
# Use another query when relationship uses a secondary table
7878
self_model = relationship.parent.entity
7979

80-
self_model_key_label = relationship.local_remote_pairs[0][1].key
81-
related_model_key_label = relationship.local_remote_pairs[1][1].key
80+
self_model_key_label = str(relationship.local_remote_pairs[0][1].key)
81+
related_model_key_label = str(relationship.local_remote_pairs[1][1].key)
8282

83-
self_model_key = relationship.local_remote_pairs[0][0].key
84-
related_model_key = relationship.local_remote_pairs[1][0].key
83+
self_model_key = str(relationship.local_remote_pairs[0][0].key)
84+
related_model_key = str(relationship.local_remote_pairs[1][0].key)
8585

8686
remote_to_use = relationship.local_remote_pairs[0][1]
8787
query_keys = tuple([item[0] for item in keys])

src/strawberry_sqlalchemy_mapper/mapper.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,18 @@ async def resolve(self, info: Info):
517517
)
518518
else:
519519
# If has a secondary table, gets only the first ID as additional IDs require a separate query
520-
local_remote_pairs_secondary_table_local = relationship.local_remote_pairs[
521-
0][0]
522-
relationship_key = tuple(
523-
[
524-
getattr(
525-
self, str(local_remote_pairs_secondary_table_local.key)),
526-
]
527-
)
520+
relationship_key = ()
521+
if relationship.local_remote_pairs:
522+
local_remote_pairs_secondary_table_local = relationship.local_remote_pairs[0][0]
523+
relationship_key = tuple(
524+
[
525+
getattr(
526+
self, str(local_remote_pairs_secondary_table_local.key)),
527+
]
528+
)
529+
return relationship_key
530+
531+
528532

529533
if any(item is None for item in relationship_key):
530534
if relationship.uselist:

0 commit comments

Comments
 (0)