Skip to content

Commit 5ad3534

Browse files
iurisilviobasepi
andauthored
Fix asyncpg tests to make it compatible with asyncpg>=0.29 (#1935)
* Fix asyncpg get_query to make it compatible with asyncpg>=0.29 * Keep testing with asyncpg<=0.28 * Upgrade flake8 in pre-commit * Remove 0.28 test from PR framework list --------- Co-authored-by: Colton Myers <colton@basepi.net>
1 parent 05332cd commit 5ad3534

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

.ci/.matrix_framework_full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ FRAMEWORK:
6767
- aiohttp-3.0
6868
- aiohttp-newest
6969
- aiopg-newest
70+
- asyncpg-0.28
7071
- asyncpg-newest
7172
- tornado-newest
7273
- starlette-0.13

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
language_version: python3
1212
exclude: "(tests/utils/stacks/linenos.py|tests/utils/stacks/linenos2.py|tests/contrib/grpc/grpc_app/.*pb2.*.py)"
1313
- repo: https://github.com/PyCQA/flake8
14-
rev: 5.0.4
14+
rev: 6.1.0
1515
hooks:
1616
- id: flake8
1717
exclude: "(tests/utils/stacks/linenos.py|tests/utils/stacks/linenos2.py|tests/contrib/grpc/grpc_app/.*pb2.*.py)"

elasticapm/contrib/asgi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ async def __call__(self, scope: "Scope", receive: "ASGIReceiveCallable", send: "
9292
body = str(body_raw, errors="ignore")
9393

9494
# Dispatch to the ASGI callable
95-
async def wrapped_receive():
95+
async def new_wrapped_receive():
9696
if messages:
9797
return messages.pop(0)
9898

9999
# Once that's done we can just await any other messages.
100100
return await receive()
101101

102+
wrapped_receive = new_wrapped_receive
103+
102104
await set_context(lambda: self.get_data_from_request(scope, constants.TRANSACTION, body), "request")
103105

104106
try:

elasticapm/instrumentation/packages/asyncio/asyncpg.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ class AsyncPGInstrumentation(AsyncAbstractInstrumentedModule):
5555
("asyncpg.protocol.protocol", "Protocol.copy_out"),
5656
]
5757

58-
def get_query(self, method, args):
58+
def get_query(self, method, args, kwargs=None):
5959
if method in ["Protocol.query", "Protocol.copy_in", "Protocol.copy_out"]:
6060
return args[0]
61-
else:
61+
elif args:
6262
return args[0].query
63+
else:
64+
# asyncpg>=0.29 pass data as kwargs
65+
return kwargs["state"].query
6366

6467
async def call(self, module, method, wrapped, instance, args, kwargs):
65-
query = self.get_query(method, args)
68+
query = self.get_query(method, args, kwargs)
6669
name = extract_signature(query)
6770
sql_string = shorten(query, string_length=10000)
6871
context = {"db": {"type": "sql", "statement": sql_string}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
asyncpg==0.28
2+
-r reqs-base.txt

0 commit comments

Comments
 (0)