Skip to content

should_retry_stop does not play nice with tenacity #49

Open
@tommyjcarpenter

Description

@tommyjcarpenter

we hit this stacktrace today:

  File "/home/ubuntu/dev/python/merq/util/opsgenie.py", line 37, in create_alert
    create_response = get_alert_api().create_alert(create_alert_payload=body)
  File "/home/ubuntu/dev/python/venv_3.7/lib/python3.7/site-packages/opsgenie_sdk/api/alert/__init__.py", line 1136, in create_alert
    (data) = self.create_alert_with_http_info(create_alert_payload, **kwargs)  # noqa: E501
  File "/home/ubuntu/dev/python/venv_3.7/lib/python3.7/site-packages/opsgenie_sdk/api/alert/__init__.py", line 1211, in create_alert_with_http_info
    collection_formats=collection_formats)
  File "/home/ubuntu/dev/python/venv_3.7/lib/python3.7/site-packages/opsgenie_sdk/api_client.py", line 429, in call_api
    _preload_content, _request_timeout, _host)
  File "/home/ubuntu/dev/python/venv_3.7/lib/python3.7/site-packages/opsgenie_sdk/api_client.py", line 219, in __call_api
    raise exception
  File "/home/ubuntu/dev/python/venv_3.7/lib/python3.7/site-packages/opsgenie_sdk/api_client.py", line 203, in __call_api
    _request_timeout=_request_timeout)
  File "/home/ubuntu/dev/python/venv_3.7/lib/python3.7/site-packages/tenacity/__init__.py", line 330, in call
    start_time=start_time)
  File "/home/ubuntu/dev/python/venv_3.7/lib/python3.7/site-packages/tenacity/__init__.py", line 292, in iter
    delay_since_first_attempt):
TypeError: should_retry_stop() takes 2 positional arguments but 3 were given
Command exited with non-zero status 1
1.62user 0.51system 5:52.42elapsed 0%CPU (0avgtext+0avgdata 106140maxresident)k
0inputs+8424outputs (0major+29116minor)pagefaults 0swaps

I tried to dig into the code the best I can. I traced it to probably: https://github.com/opsgenie/opsgenie-python-sdk/pull/29/files

The old function there was

 self.retrying = tenacity.Retrying(stop=tenacity.stop_after_attempt(configuration.retry_count),

This stop function is provided by tenacity and is an instance of their abstract base class: https://github.com/jd/tenacity/blob/master/tenacity/stop.py#L24

This Opsgenie PR above replaces it with

def should_retry_stop(self, retry_state):
        if self.configuration.retry_enabled and retry_state.attempt_number <= self.configuration.retry_count and retry_state.seconds_since_start <= self.configuration.retry_max_delay:
            return False

        return True

however self here refers to the OpsGenie API object; it is probably not an instance of the tenacity base class: https://github.com/jd/tenacity/blob/master/tenacity/stop.py#L78

it seems like their base class requires __call__ and thats it?

I tried digging into what parameters are exactly passed to the stop function; I think its around here: https://github.com/jd/tenacity/blob/master/tenacity/__init__.py#L373

however I got lost in the rabbithole

my only guess is if self_retry_stop was not a class method but just a method, it might work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions