jpetrucciani / hubspot3

python3.6+ hubspot client based on hapipy, but modified to use the newer endpoints and non-legacy python
MIT License
146 stars 72 forks source link

No verbose output to log in case of retries #98

Open advance512 opened 4 years ago

advance512 commented 4 years ago

When using the base client (we extended it for the Hubspot Associations API), we see the following in our logs:

2020-05-13 23:09:51,608 [22/#7f68ac2b2ae0] WARNING in base._call_raw:323: Too many retries for /crm-associations/v1/associations/123456/HUBSPOT_DEFINED/1? 2020-05-13 23:09:52,662 [22/#7f68ac2b2ae0] WARNING in base._call_raw:323: Too many retries for /crm-associations/v1/associations/123456/HUBSPOT_DEFINED/1? 2020-05-13 23:09:53,722 [22/#7f68ac2b2ae0] WARNING in base._call_raw:323: Too many retries for /crm-associations/v1/associations/123456/HUBSPOT_DEFINED/1?

Further in the logs, there no log output of any kind explaining what issue was encountered, what HTTP status code was returned, what error was encountered. No exception is thrown, and eventually (after 2-3 tries) the function using the BaseClient just returns None.

Looking at the code:

            except HubspotError as exception:
                if try_count > num_retries:
                    logging.warning("Too many retries for {}".format(url))
                    raise
                # Don't retry errors from 300 to 499
                if (
                    exception.result
                    and exception.result.status >= 300
                    and exception.result.status < 500
                ):
                    raise
                self._prepare_request_retry(method, url, headers, data)
                self.log.warning(
                    "HubspotError {} calling {}, retrying".format(
                        exception, url
                    )
                )
            # exponential back off - wait 0 seconds, 1 second, 3 seconds, 7 seconds, 15 seconds, etc
            time.sleep((pow(2, try_count - 1) - 1) * self.sleep_multiplier)

it seems like an exception should have indeed been thrown, so I am not certain why I don't see it outside. Anyways, I see the self.log.warning() call and I wonder why this output is not written to the log.

Is there any way to configure hubspot3 to print this warning to log in case of an error causing a retry?