diff --git a/aws_advanced_python_wrapper/mysql_driver_dialect.py b/aws_advanced_python_wrapper/mysql_driver_dialect.py index 0335df4d..76a6ff11 100644 --- a/aws_advanced_python_wrapper/mysql_driver_dialect.py +++ b/aws_advanced_python_wrapper/mysql_driver_dialect.py @@ -131,8 +131,18 @@ def get_connection_from_obj(self, obj: object) -> Any: if isinstance(obj, CMySQLCursor): try: - if isinstance(obj._cnx, CMySQLConnection) or isinstance(obj._cnx, MySQLConnection): - return obj._cnx + conn = None + + if hasattr(obj, '_cnx'): + conn = obj._cnx + elif hasattr(obj, '_connection'): + conn = obj._connection + if conn is None: + return None + + if isinstance(conn, CMySQLConnection) or isinstance(conn, MySQLConnection): + return conn + except ReferenceError: return None