Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit b005af1

Browse files
fix: Retry only GET requests
1 parent 69a924f commit b005af1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

postgrest/_sync/request_builder.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,15 @@ def execute(self) -> APIResponse[_ReturnT]:
8383
else:
8484
raise APIError(r.json())
8585
except (TimeoutException, NetworkError, ReadError) as e:
86-
# Retry for request API calls.
87-
if self.attempt < self.max_retries:
86+
# Retry only GET requests because they are read-only operations.
87+
# Resubmitting DML statements after connection errors can lead to potential blocking sessions.
88+
# This is because the DML operation may have already executed successfully on the database,
89+
# but the client lost the connection before receiving confirmation.
90+
if self.attempt < self.max_retries and self.http_method == "GET":
8891
self.attempt += 1
8992
self.execute()
93+
else:
94+
self.attempt = 1
9095
except ValidationError as e:
9196
raise APIError(r.json()) from e
9297
except JSONDecodeError:

0 commit comments

Comments
 (0)