You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in advance: I've looked at the past issues and PRs in this repo, looking for terms like "stateful" and "idempotent" and did not see anything related to my issue. Sorry if I missed it. Also I've had a quick glance at the doc but don't know it inside and out.
The below request might be out of scope for tenacity, because, as will be seen below, the issue is due to a bad pattern in the code I was looking at.
But I'll still share what happened to me today, and maybe that can give rise to a nice feature for tenacity.
I'll start with the result: tedious debugging because the traceback was not showing the actual, relevant issue.
The reason is that the retried code was not idempotent, specifically the decorated method deleted a class attribute, which can work without error at most once, while the nb of retries was 3.
Below is a MRE:
# python==3.12.7, tenacity==9.0.0fromtenacityimportstop_after_attempt, retryclassC:
def__init__(self):
self.a=""@retry(stop=stop_after_attempt(3))deff(self):
delself.a# represents a non idempotent action1/0# represents the actual prod errorC().f() # AttributeError: 'C' object has no attribute 'a'
In a Machine Learning context, del is quite common to clean up memory and so this is a real use case.
One way to avoid this is to decorate the minimal necessary code and avoid the above pattern, or use features like retry_if_exception_type but I'm wondering if it would be possible for tenacity to issue a warning log whenever there are > 1 error types encountered across all the retries
The text was updated successfully, but these errors were encountered:
Hi,
in advance: I've looked at the past issues and PRs in this repo, looking for terms like "stateful" and "idempotent" and did not see anything related to my issue. Sorry if I missed it. Also I've had a quick glance at the doc but don't know it inside and out.
The below request might be out of scope for
tenacity
, because, as will be seen below, the issue is due to a bad pattern in the code I was looking at.But I'll still share what happened to me today, and maybe that can give rise to a nice feature for tenacity.
I'll start with the result: tedious debugging because the traceback was not showing the actual, relevant issue.
The reason is that the retried code was not idempotent, specifically the decorated method deleted a class attribute, which can work without error at most once, while the nb of retries was 3.
Below is a MRE:
In a Machine Learning context,
del
is quite common to clean up memory and so this is a real use case.One way to avoid this is to decorate the minimal necessary code and avoid the above pattern, or use features like
retry_if_exception_type
but I'm wondering if it would be possible for tenacity to issue a warning log whenever there are > 1 error types encountered across all the retriesThe text was updated successfully, but these errors were encountered: