Skip to content

Add __iter__ method to TracedCursorProxy#4427

Open
lrafeei wants to merge 4 commits intoopen-telemetry:mainfrom
lrafeei:main
Open

Add __iter__ method to TracedCursorProxy#4427
lrafeei wants to merge 4 commits intoopen-telemetry:mainfrom
lrafeei:main

Conversation

@lrafeei
Copy link
Copy Markdown

@lrafeei lrafeei commented Apr 13, 2026

Description

During the upgrade to support wrapt v2.0, the inherited class for TracedCursorProxy in opentelemetry/instrumentation/dbapi/__init__.py was changed to BaseObjectProxy. One of the changes in wrapt v2.0 is that the BaseObjectProxy no longer provides a proxy implementation for the __iter__() method. The issue with this is that the DBAPI cursor is an iterable, so this breaks any potential instrumentation relying on this. As a fix, an __iter__() method is added to the TracedCursorProxy class.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Existing tests re-run
  • A new test was added to test this functionality

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 13, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@lrafeei lrafeei marked this pull request as ready for review April 13, 2026 23:59
span = spans_list[0]
self.assertEqual(span.attributes[DB_STATEMENT], "Test query")

def test_executemany_iterable_cursor(self):
Copy link
Copy Markdown
Contributor

@xrmx xrmx Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think pylint will warn that this can be made a staticmethod, you can add a self.assertTrue("no raise") or disable the rule for the method. You can run tox -e lint-instrumentation-dbapi locally

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up. Fixed and pushed up

@lrafeei lrafeei requested a review from xrmx April 14, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants