Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit 2bf2fb3

Browse files
fix: fix error when cursor.lastrowid doesnt exist (#281)
## Which problem is this PR solving? - closes #278 ## Short description of the changes - only add `db.last_insert_id` if `lastrowid` exists on the Cursor object. A similar fix is already in place for [Flask middleware](https://github.com/honeycombio/beeline-python/blob/main/beeline/middleware/flask/__init__.py#L113). When using psycopg2, the `lastrowid` existed but came through as 0. When using psycopg3, the `lastrowid` doesn't exist, which caused an exception. The below screenshot shows a before and after for this fix. ![before-and-after-lastrowid-fix](https://github.com/honeycombio/beeline-python/assets/29520003/aa5f24ce-9627-482d-b9dc-6bed3775ddc0)
1 parent 8eb871f commit 2bf2fb3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

beeline/middleware/django/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __call__(self, execute, sql, params, many, context):
7272
finally:
7373
if vendor in ('postgresql', 'mysql'):
7474
beeline.add_context({
75-
"db.last_insert_id": context['cursor'].cursor.lastrowid,
75+
"db.last_insert_id": getattr(context['cursor'].cursor, 'lastrowid', None),
7676
"db.rows_affected": context['cursor'].cursor.rowcount,
7777
})
7878

0 commit comments

Comments
 (0)