Skip to content

Commit

Permalink
[Mega-Linter] Apply linters fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hmstepanek authored and github-actions[bot] committed Dec 9, 2024
1 parent beced7b commit 387c153
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions newrelic/hooks/database_aiomysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@

from newrelic.api.database_trace import register_database_client
from newrelic.api.function_trace import FunctionTrace
from newrelic.common.object_wrapper import ObjectProxy, wrap_object, wrap_function_wrapper
from newrelic.common.object_names import callable_name

from newrelic.hooks.database_dbapi2_async import AsyncConnectionFactory as DBAPI2AsyncConnectionFactory
from newrelic.hooks.database_dbapi2_async import AsyncConnectionWrapper as DBAPI2AsyncConnectionWrapper
from newrelic.hooks.database_dbapi2_async import AsyncCursorWrapper as DBAPI2AsyncCursorWrapper
from newrelic.common.object_wrapper import (
ObjectProxy,
wrap_function_wrapper,
wrap_object,
)
from newrelic.hooks.database_dbapi2_async import (
AsyncConnectionFactory as DBAPI2AsyncConnectionFactory,
)
from newrelic.hooks.database_dbapi2_async import (
AsyncConnectionWrapper as DBAPI2AsyncConnectionWrapper,
)
from newrelic.hooks.database_dbapi2_async import (
AsyncCursorWrapper as DBAPI2AsyncCursorWrapper,
)


class AsyncCursorContextManagerWrapper(ObjectProxy):
Expand All @@ -36,9 +45,7 @@ def __init__(self, context_manager, dbapi2_module, connect_params, cursor_args):

async def __aenter__(self):
cursor = await self.__wrapped__.__aenter__()
return self.__cursor_wrapper__(
cursor, self._nr_dbapi2_module, self._nr_connect_params, self._nr_cursor_args
)
return self.__cursor_wrapper__(cursor, self._nr_dbapi2_module, self._nr_connect_params, self._nr_cursor_args)

async def __aexit__(self, exc, val, tb):
return await self.__wrapped__.__aexit__(exc, val, tb)
Expand Down Expand Up @@ -67,8 +74,7 @@ async def _wrap_pool__acquire(wrapped, instance, args, kwargs):


def instance_info(args, kwargs):
def _bind_params(host=None, user=None, password=None, db=None,
port=None, *args, **kwargs):
def _bind_params(host=None, user=None, password=None, db=None, port=None, *args, **kwargs):
return host, port, db

host, port, db = _bind_params(*args, **kwargs)
Expand All @@ -77,15 +83,20 @@ def _bind_params(host=None, user=None, password=None, db=None,


def instrument_aiomysql(module):
register_database_client(module, database_product='MySQL',
quoting_style='single+double', explain_query='explain',
explain_stmts=('select',), instance_info=instance_info)
register_database_client(
module,
database_product="MySQL",
quoting_style="single+double",
explain_query="explain",
explain_stmts=("select",),
instance_info=instance_info,
)

# Only instrument the connect method directly, don't instrument
# Connection. This follows the DBAPI2 spec and what was done for
# PyMySQL which this library is based on.

wrap_object(module, 'connect', AsyncConnectionFactory, (module,))
wrap_object(module, "connect", AsyncConnectionFactory, (module,))


def instrument_aiomysql_pool(module):
Expand Down

0 comments on commit 387c153

Please sign in to comment.