Skip to content

Commit 72096e8

Browse files
author
Max Wang
committed
update per ai comments
1 parent 38b1843 commit 72096e8

3 files changed

Lines changed: 7 additions & 16 deletions

File tree

examples/advanced/file_upload.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def generate_test_pdf(size_mb: int = 10) -> Path:
153153
return test_file
154154

155155

156-
def backoff(op, *, delays=(0, 2, 5, 10), retry_status=(400, 403, 404, 409, 412, 429, 500, 502, 503, 504)):
156+
def backoff(op, *, delays=(0, 2, 5, 10)):
157157
last = None
158158
for d in delays:
159159
if d:
@@ -162,11 +162,6 @@ def backoff(op, *, delays=(0, 2, 5, 10), retry_status=(400, 403, 404, 409, 412,
162162
return op()
163163
except Exception as ex: # noqa: BLE001
164164
last = ex
165-
r = getattr(ex, "response", None)
166-
code = getattr(r, "status_code", None)
167-
if isinstance(ex, requests.exceptions.HTTPError) and code in retry_status:
168-
continue
169-
# For non-HTTP errors just retry the schedule
170165
continue
171166
if last:
172167
raise last
@@ -245,7 +240,7 @@ def ensure_file_attribute_generic(schema_name: str, label: str, key_prefix: str)
245240
}
246241
try:
247242
url = f"{odata.api}/EntityDefinitions({meta_id})/Attributes"
248-
r = backoff(lambda: odata._request("post", url, json=payload), delays=ATTRIBUTE_VISIBILITY_DELAYS)
243+
backoff(lambda: odata._request("post", url, json=payload), delays=ATTRIBUTE_VISIBILITY_DELAYS)
249244
print({f"{key_prefix}_file_attribute_created": True})
250245
time.sleep(2)
251246
return True

examples/advanced/walkthrough.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,15 @@ class Priority(IntEnum):
3838
HIGH = 3
3939

4040

41-
def backoff(op, *, delays=(0, 2, 5, 10), retry_status=(400, 403, 404, 409, 412, 429, 500, 502, 503, 504)):
41+
def backoff(op, *, delays=(0, 2, 5, 10)):
4242
last = None
43-
for delay in delays:
44-
if delay:
45-
time.sleep(delay)
43+
for d in delays:
44+
if d:
45+
time.sleep(d)
4646
try:
4747
return op()
4848
except Exception as ex: # noqa: BLE001
4949
last = ex
50-
resp = getattr(ex, "response", None)
51-
code = getattr(resp, "status_code", None)
52-
if isinstance(ex, requests.exceptions.HTTPError) and code in retry_status:
53-
continue
5450
continue
5551
if last:
5652
raise last

src/PowerPlatform/Dataverse/data/_odata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ def _optionset_map(self, table_schema_name: str, attr_logical: str) -> Optional[
10041004
except HttpError as err:
10051005
if getattr(err, "status_code", None) == 404:
10061006
if attempt < max_attempts:
1007-
# Exponential backoff: 0.4s, 0.8s, 1.6s, ...
1007+
# Exponential backoff: 0.4s, 0.8s, 1.6s, 3.2s
10081008
time.sleep(backoff_seconds * (2 ** (attempt - 1)))
10091009
continue
10101010
raise RuntimeError(

0 commit comments

Comments
 (0)