Skip to content

Commit a47ae0f

Browse files
committed
Fix an httpx crash caused by import ordering issues.
1 parent 4f7af23 commit a47ae0f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

newrelic/hooks/external_httpx.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ async def async_send_wrapper(wrapped, instance, args, kwargs):
103103

104104
@property
105105
def nr_first_event_hooks(self):
106-
return getattr(self, "_nr_event_hooks")
106+
if not hasattr(self, "_nr_event_hooks"):
107+
# This branch should only be hit if agent initialize is called after
108+
# the initialization of the http client
109+
self._event_hooks = vars(self)["_event_hooks"]
110+
del vars(self)["_event_hooks"]
111+
return self._nr_event_hooks
107112

108113

109114
@nr_first_event_hooks.setter
@@ -114,7 +119,12 @@ def nr_first_event_hooks(self, value):
114119

115120
@property
116121
def nr_first_event_hooks_async(self):
117-
return getattr(self, "_nr_event_hooks")
122+
if not hasattr(self, "_nr_event_hooks"):
123+
# This branch should only be hit if agent initialize is called after
124+
# the initialization of the http client
125+
self._event_hooks = vars(self)["_event_hooks"]
126+
del vars(self)["_event_hooks"]
127+
return self._nr_event_hooks
118128

119129

120130
@nr_first_event_hooks_async.setter

0 commit comments

Comments
 (0)