Skip to content

Commit 49d3503

Browse files
fix: handle circular import in psycopg integration (#7796)
This fix resolves #7241 by catching the `AttributeError` raised by a circular import in the psycopg integration that can arise under ddtrace-run. This is the appropriate course of action because the presence of an `except: pass` around this import indicates that it is possible for the integration to function satisfactorily without the import working. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that. --------- Co-authored-by: William Conti <[email protected]>
1 parent 6de31a4 commit 49d3503

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

ddtrace/contrib/psycopg/patch.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
# using unwrap
4040
_original_connect = psycopg_import.Connection.__dict__["connect"]
4141
_original_async_connect = psycopg_import.AsyncConnection.__dict__["connect"]
42-
except ImportError:
42+
# AttributeError can happen due to circular imports under certain integration methods
43+
except (ImportError, AttributeError):
4344
pass
4445

4546

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
psycopg: This fix resolves an issue where a circular import of the psycopg library could
5+
cause a crash during monkeypatching.

0 commit comments

Comments
 (0)