Skip to content

Commit 4a44be7

Browse files
fix: pagination rebase error (#359)
1 parent 9a9dfec commit 4a44be7

8 files changed

Lines changed: 26 additions & 34 deletions

File tree

indico/client/request.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,23 @@ def __init__(self, query: str, variables: "Optional[AnyDict]" = None):
9999
self.has_next_page = True
100100
super().__init__(query, variables=variables)
101101

102-
def process_response(
102+
def parse_payload(
103103
self, response: "AnyDict", nested_keys: "Optional[List[str]]" = None
104104
) -> "Any":
105-
raw_response: "AnyDict" = cast("AnyDict", super().process_response(response))
105+
raw_response: "AnyDict" = cast("AnyDict", super().parse_payload(response))
106+
106107
if nested_keys:
107-
_pg = raw_response
108+
composite = raw_response
108109
for key in nested_keys:
109-
if key not in _pg.keys():
110+
if key not in composite.keys():
110111
raise IndicoInputError(
111112
f"Nested key not found in response: {key}",
112113
)
113-
_pg = _pg[key]
114-
_pg = _pg["pageInfo"]
114+
composite = composite[key]
115+
116+
_pg = composite.get("pageInfo")
115117
else:
116-
_pg = next(iter(response.values()))["pageInfo"]
118+
_pg = next(iter(raw_response.values())).get("pageInfo")
117119

118120
if not _pg:
119121
raise ValueError("The supplied GraphQL must include 'pageInfo'.")

indico/queries/datasets.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ def __init__(
8888
},
8989
)
9090

91-
def process_response(
92-
self, response: "Payload", _: "Optional[List[str]]" = None
93-
) -> "List[Dataset]":
91+
def process_response(self, response: "Payload") -> "List[Dataset]":
9492
response = super().parse_payload(response)
9593
return [Dataset(**dataset) for dataset in response["datasetsPage"]["datasets"]]
9694

indico/queries/document_report.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ def __init__(
7070
}
7171
super().__init__(self.query, variables=variables)
7272

73-
def process_response(
74-
self, response: "Payload", _: "Optional[List[str]]" = None
75-
) -> "List[DocumentReport]":
73+
def process_response(self, response: "Payload") -> "List[DocumentReport]":
7674
return _DocumentReportList(
7775
**super().parse_payload(response)["submissionsLog"]
7876
).submissions

indico/queries/example.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ def __init__(
7373
variables=variables,
7474
)
7575

76-
def process_response(
77-
self, response: "Payload", _: "Optional[List[str]]" = None
78-
) -> "List[Example]":
76+
def process_response(self, response: "Payload") -> "List[Example]":
7977
example_page = super().parse_payload(response)["modelGroups"]["modelGroups"][0]
8078
return [Example(**s) for s in example_page["pagedExamples"]["examples"]]

indico/queries/gallery.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import TYPE_CHECKING, cast
1+
from typing import TYPE_CHECKING
22

33
from indico.client.request import GraphQLRequest, PagedRequest
44
from indico.types.component_blueprint import BlueprintPage, BlueprintTags
55

66
if TYPE_CHECKING: # pragma: no cover
7-
from typing import Any, List, Optional
7+
from typing import Any, Optional
88

99
from indico.filters import ComponentBlueprintFilter
1010
from indico.typing import Payload
@@ -76,10 +76,8 @@ def __init__(
7676
},
7777
)
7878

79-
def process_response(
80-
self, response: "Payload", _: "Optional[List[str]]" = None
81-
) -> "BlueprintPage":
82-
response = super().process_response(
79+
def process_response(self, response: "Payload") -> "BlueprintPage":
80+
response = super().parse_payload(
8381
response, nested_keys=["gallery", "component", "blueprintsPage"]
8482
)
8583
return BlueprintPage(
@@ -121,7 +119,11 @@ def __init__(self, component_family: "Optional[str]" = None):
121119
)
122120

123121
def process_response(self, response: "Payload") -> "BlueprintTags":
124-
response = cast(Payload, super().process_response(response))
125122
return BlueprintTags(
126-
tags=[tag for tag in response["gallery"]["component"]["availableTags"]]
123+
tags=[
124+
tag
125+
for tag in super().parse_payload(response)["gallery"]["component"][
126+
"availableTags"
127+
]
128+
]
127129
)

indico/queries/model_groups/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self, model_group_id: int):
106106

107107
def process_response(self, response: "Payload") -> "AnyDict":
108108
raw_response: "AnyDict" = json.loads(
109-
super().process_response(response)["modelGroups"]["modelGroups"][0][
109+
super().parse_payload(response)["modelGroups"]["modelGroups"][0][
110110
"selectedModel"
111111
]["evaluation"]["metrics"]
112112
)

indico/queries/submission.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ def __init__(
149149
},
150150
)
151151

152-
def process_response(
153-
self, response: "Payload", _: "Optional[List[str]]" = None
154-
) -> "List[Submission]":
152+
def process_response(self, response: "Payload") -> "List[Submission]":
155153
return [
156154
Submission(**s)
157155
for s in super().parse_payload(response)["submissions"]["submissions"]

indico/queries/usermetrics.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ def __init__(
118118
}
119119
super().__init__(self.query, variables=variables)
120120

121-
def process_response(
122-
self, response: "Payload", _: "Optional[List[str]]" = None
123-
) -> "List[UserSnapshot]":
121+
def process_response(self, response: "Payload") -> "List[UserSnapshot]":
124122
return _PagedUserSnapshots(
125123
**super().parse_payload(response)["userSnapshot"]
126124
).results
@@ -180,9 +178,7 @@ def __init__(
180178
}
181179
super().__init__(self.query, variables=variables)
182180

183-
def process_response(
184-
self, response: "Payload", _: "Optional[List[str]]" = None
185-
) -> "List[UserChangelog]":
181+
def process_response(self, response: "Payload") -> "List[UserChangelog]":
186182
return _PagedUserChangelog(
187183
**super().parse_payload(response)["userChangelog"]
188184
).results

0 commit comments

Comments
 (0)