-
Notifications
You must be signed in to change notification settings - Fork 234
Closed
Labels
agent-pythoncommunityIssues opened by the communityIssues opened by the communitytriageIssues awaiting triageIssues awaiting triage
Description
Description
When using Django with the recommended psycopg[c] v3 adapter and Elastic APM enabled, executing a QuerySet.iterator() fails with: TypeError: keyword not supported: prepare.
This occurs because psycopg v3’s server-side cursor implementation rejects the prepare=keyword argument, which is being passed through Elastic APM's database instrumentation.
To Reproduce
- Install Django with the recommended PostgreSQL adapter (psycopg[c] v3.2.12).
- Enable Elastic APM in the Django project.
- Execute a Django query using QuerySet.iterator(), for example:
for obj in MyModel.objects.iterator():
...Environment
- OS: Linux, Debian
- Python version: 3.12.12
- Framework and version Django 4.2
- APM Server version: 9
- Agent version: 6.24.0
- Server side cursors: enabled
Expected behavior:
The queryset should be processed normally using a server-side cursor without errors.
Actual behavior:
TypeError is raised: keyword not supported: prepare
psycopg/_server_cursor.py in execute at line 88
) -> Self:
"""
Open a cursor to execute a query to the database.
"""
if kwargs: # <---- here {"prepare": None}
raise TypeError(f"keyword not supported: {list(kwargs)[0]}")
if self._pgconn.pipeline_status:
raise e.NotSupportedError(
"server-side cursors not supported in pipeline mode"
)Additional context
- The error does not occur if Elastic APM is disabled.
- The error does not occur when using the not-recommended psycopg v2
- The issue appears to be caused by Elastic APM adding a
prepare=Noneparameter during its instrumentation of database queries.
Metadata
Metadata
Assignees
Labels
agent-pythoncommunityIssues opened by the communityIssues opened by the communitytriageIssues awaiting triageIssues awaiting triage