Skip to content

Commit

Permalink
Merge pull request #276 from GeoNode/handle_multiple_replies
Browse files Browse the repository at this point in the history
[Fixes #275] Handle multiple replies generated for same request
  • Loading branch information
Gpetrak authored Nov 4, 2024
2 parents b01a542 + 4a3bc5c commit 8372943
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/qgis_geonode/apiclient/geonode_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,9 @@ def run(self) -> bool:
)
multipart.setParent(qt_reply)
request_id = qt_reply.property("requestId")
self._pending_replies[request_id] = (0, qt_reply)
self._pending_replies[request_id] = network.PendingReply(
0, qt_reply, False
)
else:
self._all_requests_finished.emit()
loop_forcibly_ended = not bool(event_loop_result.result)
Expand Down
27 changes: 22 additions & 5 deletions src/qgis_geonode/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class HttpMethod(enum.Enum):
PATCH = "PATCH"


@dataclasses.dataclass()
class PendingReply:
index: int
reply: qgis.core.QgsNetworkReplyContent
fullfilled: bool = False


@dataclasses.dataclass()
class ParsedNetworkReply:
http_status_code: int
Expand Down Expand Up @@ -168,7 +175,10 @@ def run(self) -> bool:
# its network access manager - this can be used to keep track of
# replies
request_id = qt_reply.property("requestId")
self._pending_replies[request_id] = (index, qt_reply)
# self._pending_replies[request_id] = [index, qt_reply, False]
self._pending_replies[request_id] = PendingReply(
index, qt_reply, False
)
else:
self._all_requests_finished.emit()
loop_forcibly_ended = not bool(event_loop_result.result)
Expand Down Expand Up @@ -235,14 +245,21 @@ def _handle_request_finished(self, qgis_reply: qgis.core.QgsNetworkReplyContent)
then uses that to gain access to the response body.
"""

qt_reply = None
try:
index, qt_reply = self._pending_replies[qgis_reply.requestId()]
pending_reply = self._pending_replies[qgis_reply.requestId()]
# See https://github.com/GeoNode/QGISGeoNodePlugin/issues/275
if not pending_reply.fullfilled:
index = pending_reply.index
qt_reply = pending_reply.reply
pending_reply.fullfilled = True

except KeyError:
pass # we are not managing this request, ignore
else:
parsed = parse_qt_network_reply(qt_reply)
self.response_contents[index] = parsed
if qt_reply:
parsed = parse_qt_network_reply(qt_reply)
self.response_contents[index] = parsed
self._num_finished += 1
if self._num_finished >= len(self.requests_to_perform):
self._all_requests_finished.emit()
Expand Down

0 comments on commit 8372943

Please sign in to comment.