Skip to content

Commit

Permalink
Fix/dbt deps retry none answer (#4225)
Browse files Browse the repository at this point in the history
* Fix issue #4178
Allow retries when the answer is None

* Include fix for #4178
Allow retries when the answer from dbt deps is None

* Add link to the PR

* Update exception and shorten line size

* Add test when dbt deps returns None
  • Loading branch information
b-per authored Nov 8, 2021
1 parent dd84f9a commit f20e83a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Fixes
- Changes unit tests using `assertRaisesRegexp` to `assertRaisesRegex` ([#4136](https://github.com/dbt-labs/dbt-core/issues/4132), [#4136](https://github.com/dbt-labs/dbt-core/pull/4136))
- Allow retries when the answer from a `dbt deps` is `None` ([#4178](https://github.com/dbt-labs/dbt-core/issues/4178))

### Under the hood
- Bump artifact schema versions for 1.0.0: manifest v4, run results v4, sources v3. Notable changes: schema test + data test nodes are renamed to generic test + singular test nodes; freshness threshold default values ([#4191](https://github.com/dbt-labs/dbt-core/pull/4191))
Expand All @@ -23,6 +24,7 @@ Contributors:
- [@Kayrnt](https://github.com/Kayrnt) ([#4136](https://github.com/dbt-labs/dbt-core/pull/4170))
- [@VersusFacit](https://github.com/VersusFacit) ([#4104](https://github.com/dbt-labs/dbt-core/pull/4104))
- [@joellabes](https://github.com/joellabes) ([#4104](https://github.com/dbt-labs/dbt-core/pull/4104))
- [@b-per](https://github.com/b-per) ([#4225](https://github.com/dbt-labs/dbt-core/pull/4225))


## dbt-core 1.0.0b2 (October 25, 2021)
Expand Down
4 changes: 4 additions & 0 deletions core/dbt/clients/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def _get(path, registry_base_url=None):
logger.debug('Response from registry: GET {} {}'.format(url,
resp.status_code))
resp.raise_for_status()
if resp is None:
raise requests.exceptions.ContentDecodingError(
'Request error: The response is None', response=resp
)
return resp.json()


Expand Down
6 changes: 5 additions & 1 deletion core/dbt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,11 @@ def _connection_exception_retry(fn, max_attempts: int, attempt: int = 0):
"""
try:
return fn()
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as exc:
except (
requests.exceptions.ConnectionError,
requests.exceptions.Timeout,
requests.exceptions.ContentDecodingError,
) as exc:
if attempt <= max_attempts - 1:
logger.debug('Retrying external call. Attempt: ' +
f'{attempt} Max attempts: {max_attempts}')
Expand Down
10 changes: 10 additions & 0 deletions test/unit/test_core_dbt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def test_connection_exception_retry_success(self):
connection_exception_retry(lambda: Counter._add_with_limited_exception(), 5)
self.assertEqual(2, counter) # 2 = original attempt plus 1 retry

def test_connection_exception_retry_success_none_response(self):
Counter._reset()
connection_exception_retry(lambda: Counter._add_with_none_exception(), 5)
self.assertEqual(2, counter) # 2 = original attempt returned None, plus 1 retry


counter:int = 0
class Counter():
Expand All @@ -37,6 +42,11 @@ def _add_with_limited_exception():
counter+=1
if counter < 2:
raise requests.exceptions.ConnectionError
def _add_with_none_exception():
global counter
counter+=1
if counter < 2:
raise requests.exceptions.ContentDecodingError
def _reset():
global counter
counter = 0

0 comments on commit f20e83a

Please sign in to comment.