Skip to content

Commit acd9a47

Browse files
committed
Misc updates after wrapt upgrade
1 parent a963ebf commit acd9a47

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

newrelic/common/object_wrapper.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121

2222
import inspect
2323

24+
from newrelic.packages.wrapt import ( # noqa: F401
25+
BaseObjectProxy,
26+
apply_patch,
27+
resolve_path,
28+
wrap_object,
29+
wrap_object_attribute,
30+
)
2431
from newrelic.packages.wrapt import BoundFunctionWrapper as _BoundFunctionWrapper
2532
from newrelic.packages.wrapt import CallableObjectProxy as _CallableObjectProxy
2633
from newrelic.packages.wrapt import FunctionWrapper as _FunctionWrapper
27-
from newrelic.packages.wrapt import ObjectProxy as _ObjectProxy
28-
from newrelic.packages.wrapt import apply_patch, resolve_path, wrap_object, wrap_object_attribute # noqa: F401
2934

3035
# We previously had our own pure Python implementation of the generic
3136
# object wrapper but we now defer to using the wrapt module as its C
@@ -44,7 +49,7 @@
4449
# ObjectProxy or FunctionWrapper should be used going forward.
4550

4651

47-
class ObjectProxy(_ObjectProxy):
52+
class ObjectProxy(BaseObjectProxy):
4853
"""
4954
This class provides method overrides for all object wrappers used by the
5055
agent. These methods allow attributes to be defined with the special prefix

newrelic/hooks/database_dbapi2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def callproc(self, procname, parameters=DEFAULT):
8989
else:
9090
return self.__wrapped__.callproc(procname)
9191

92+
def __iter__(self):
93+
return iter(self.__wrapped__)
94+
9295

9396
class ConnectionWrapper(ObjectProxy):
9497
__cursor_wrapper__ = CursorWrapper

tests/datastore_psycopg/test_cursor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def _execute(connection, cursor, row_type, wrapper):
9898
# Consume inserted records to check that returning param functions
9999
records = []
100100
while True:
101-
records.append(cursor.fetchone())
101+
records.append(await maybe_await(cursor.fetchone()))
102102
if not cursor.nextset():
103103
break
104104
assert len(records) == len(params)
@@ -140,7 +140,7 @@ async def _exercise_db(connection, row_factory=None, use_cur_context=False, row_
140140
try:
141141
cursor = connection.cursor(**kwargs)
142142
if use_cur_context:
143-
if hasattr(cursor, "__aenter__"):
143+
if hasattr(cursor.__wrapped__, "__aenter__"):
144144
async with cursor:
145145
await _execute(connection, cursor, row_type, wrapper)
146146
else:

tests/datastore_psycopg/test_register.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test():
3232
psycopg.types.json.set_json_loads(loads=lambda x: x, context=connection)
3333
psycopg.types.json.set_json_loads(loads=lambda x: x, context=cursor)
3434

35-
if hasattr(connection, "__aenter__"):
35+
if hasattr(connection.__wrapped__, "__aenter__"):
3636

3737
async def coro():
3838
async with connection:
@@ -69,7 +69,7 @@ async def test():
6969

7070
await maybe_await(cursor.execute(f"DROP TYPE if exists {type_name}"))
7171

72-
if hasattr(connection, "__aenter__"):
72+
if hasattr(connection.__wrapped__, "__aenter__"):
7373

7474
async def coro():
7575
async with connection:

tests/datastore_psycopg/test_rollback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
async def _exercise_db(connection):
5959
try:
60-
if hasattr(connection, "__aenter__"):
60+
if hasattr(connection.__wrapped__, "__aenter__"):
6161
async with connection:
6262
raise RuntimeError("error")
6363
else:

0 commit comments

Comments
 (0)