Skip to content

conn.commit() raise InterfaceError because connection instrument wrapper has no _sock member #1353

Closed
@kchow1985

Description

@kchow1985

Describe your environment Describe any aspect of your environment relevant to the problem, including your Python version, platform, version numbers of installed dependencies, information about your cloud hosting provider, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main.

instrumentation version: opentelemetry-instrumentation-pymysql 0.33b0

Steps to reproduce
When using opentelemetry-instrument command to automatically instrument pymysql

conn = pymysql.connect(...)

with conn.cursor() as cursor:
  cursor.execute(...) # run any insert statement
  conn.commit() # this line will trigger InterfaceError

Current bandaid solution:

conn = pymysql.connect(...)
conn._sock = conn._connection._sock # add this line to work around

with conn.cursor() as cursor:
  cursor.execute(...)
  conn.commit() # this line will no longer trigger InterfaceError

Tracing down the stack will show that on line 792 of the pymysql/connections/.py, the Exception will be thrown because self now refers to the wrapper instead of the internal connection object:

    def _execute_command(self, command, sql):
        """
        :raise InterfaceError: If the connection is closed.
        :raise ValueError: If no username was specified.
        """
        if not self._sock:
            raise err.InterfaceError(0, "")
        ...

If I do not instrument pymysql then this will not happen.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions