Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError when use elastic-apm #1100

Open
aryadovoy opened this issue Nov 7, 2023 · 1 comment
Open

IndexError when use elastic-apm #1100

aryadovoy opened this issue Nov 7, 2023 · 1 comment

Comments

@aryadovoy
Copy link

aryadovoy commented Nov 7, 2023

  • asyncpg version: 0.29.0
  • PostgreSQL version: 14
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : Yes
  • Python version: 3.11.6
  • Platform: Linux, 6.0.12-100.fc35.x86_64
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes
  • If you built asyncpg locally, which version of Cython did you use?: −
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : Don't know

It was OK on 0.28.0, but now I have this error. Think, it's regarding to #1043.
There is no args, so it cannot get query.

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv/lib/python3.11/site-packages/httpx/_client.py:1848: in post
    return await self.request(
.venv/lib/python3.11/site-packages/httpx/_client.py:1530: in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
.venv/lib/python3.11/site-packages/httpx/_client.py:1617: in send
    response = await self._send_handling_auth(
.venv/lib/python3.11/site-packages/httpx/_client.py:1645: in _send_handling_auth
    response = await self._send_handling_redirects(
.venv/lib/python3.11/site-packages/httpx/_client.py:1682: in _send_handling_redirects
    response = await self._send_single_request(request)
.venv/lib/python3.11/site-packages/httpx/_client.py:1719: in _send_single_request
    response = await transport.handle_async_request(request)
.venv/lib/python3.11/site-packages/httpx/_transports/asgi.py:162: in handle_async_request
    await self.app(scope, receive, send)
.venv/lib/python3.11/site-packages/fastapi/applications.py:292: in __call__
    await super().__call__(scope, receive, send)
.venv/lib/python3.11/site-packages/starlette/applications.py:122: in __call__
    await self.middleware_stack(scope, receive, send)
.venv/lib/python3.11/site-packages/elasticapm/instrumentation/packages/asyncio/starlette.py:48: in call
    return await wrapped(*args, **kwargs)
.venv/lib/python3.11/site-packages/starlette/middleware/errors.py:184: in __call__
    raise exc
.venv/lib/python3.11/site-packages/starlette/middleware/errors.py:162: in __call__
    await self.app(scope, receive, _send)
.venv/lib/python3.11/site-packages/elasticapm/contrib/starlette/__init__.py:193: in __call__
    await self.app(scope, _request_receive or receive, wrapped_send)
.venv/lib/python3.11/site-packages/starlette/middleware/sessions.py:86: in __call__
    await self.app(scope, receive, send_wrapper)
.venv/lib/python3.11/site-packages/starlette/middleware/cors.py:83: in __call__
    await self.app(scope, receive, send)
.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py:79: in __call__
    raise exc
.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py:68: in __call__
    await self.app(scope, receive, sender)
.venv/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py:20: in __call__
    raise e
.venv/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py:17: in __call__
    await self.app(scope, receive, send)
.venv/lib/python3.11/site-packages/starlette/routing.py:718: in __call__
    await route.handle(scope, receive, send)
.venv/lib/python3.11/site-packages/starlette/routing.py:276: in handle
    await self.app(scope, receive, send)
.venv/lib/python3.11/site-packages/starlette/routing.py:66: in app
    response = await func(request)
.venv/lib/python3.11/site-packages/fastapi/routing.py:273: in app
    raw_response = await run_endpoint_function(
.venv/lib/python3.11/site-packages/fastapi/routing.py:190: in run_endpoint_function
    return await dependant.call(**values)
src/app/presentation/api/consumers.py:39: in send_otp
    consumer, is_new = await ConsumerService.send_otp(uow=uow, data=data)
src/app/core/services/consumers.py:29: in send_otp
    consumer := await uow.consumers.get_by_phone(
src/app/infrastructure/db/dao/consumers.py:24: in get_by_phone
    query = await self.session.execute(
.venv/lib/python3.11/site-packages/sqlalchemy/ext/asyncio/session.py:454: in execute
    result = await greenlet_spawn(
.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py:190: in greenlet_spawn
    result = context.throw(*sys.exc_info())
.venv/lib/python3.11/site-packages/sqlalchemy/orm/session.py:2262: in execute
    return self._execute_internal(
.venv/lib/python3.11/site-packages/sqlalchemy/orm/session.py:2134: in _execute_internal
    conn = self._connection_for_bind(bind)
.venv/lib/python3.11/site-packages/sqlalchemy/orm/session.py:2001: in _connection_for_bind
    return trans._connection_for_bind(engine, execution_options)
<string>:2: in _connection_for_bind
    ???
.venv/lib/python3.11/site-packages/sqlalchemy/orm/state_changes.py:139: in _go
    ret_value = fn(self, *arg, **kw)
.venv/lib/python3.11/site-packages/sqlalchemy/orm/session.py:1126: in _connection_for_bind
    conn = bind.connect()
.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py:3264: in connect
    return self._connection_cls(self)
.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py:145: in __init__
    self._dbapi_connection = engine.raw_connection()
.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py:3288: in raw_connection
    return self.pool.connect()
.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py:452: in connect
    return _ConnectionFairy._checkout(self)
.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py:1267: in _checkout
    fairy = _ConnectionRecord.checkout(pool)
.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py:716: in checkout
    rec = pool._do_get()
.venv/lib/python3.11/site-packages/sqlalchemy/pool/impl.py:169: in _do_get
    with util.safe_reraise():
.venv/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py:146: in __exit__
    raise exc_value.with_traceback(exc_tb)
.venv/lib/python3.11/site-packages/sqlalchemy/pool/impl.py:167: in _do_get
    return self._create_connection()
.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py:393: in _create_connection
    return _ConnectionRecord(self)
.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py:678: in __init__
    self.__connect()
.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py:916: in __connect
    )._exec_w_sync_on_first_run(self.dbapi_connection, self)
.venv/lib/python3.11/site-packages/sqlalchemy/event/attr.py:473: in _exec_w_sync_on_first_run
    self(*args, **kw)
.venv/lib/python3.11/site-packages/sqlalchemy/event/attr.py:487: in __call__
    fn(*args, **kw)
.venv/lib/python3.11/site-packages/sqlalchemy/engine/create.py:704: in on_connect
    do_on_connect(dbapi_connection)
.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py:1240: in connect
    conn.await_(self.setup_asyncpg_json_codec(conn))
.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py:125: in await_only
    return current.driver.switch(awaitable)  # type: ignore[no-any-return]
.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py:185: in greenlet_spawn
    value = await result
.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py:1166: in setup_asyncpg_json_codec
    await asyncpg_connection.set_type_codec(
.venv/lib/python3.11/site-packages/asyncpg/connection.py:1339: in set_type_codec
    typeinfo = await self._introspect_type(typename, schema)
.venv/lib/python3.11/site-packages/asyncpg/connection.py:543: in _introspect_type
    rows = await self._execute(
.venv/lib/python3.11/site-packages/asyncpg/connection.py:1794: in _execute
    result, _ = await self.__execute(
.venv/lib/python3.11/site-packages/asyncpg/connection.py:1892: in __execute
    result, stmt = await self._do_execute(
.venv/lib/python3.11/site-packages/asyncpg/connection.py:1945: in _do_execute
    result = await executor(stmt, None)
.venv/lib/python3.11/site-packages/elasticapm/instrumentation/packages/asyncio/asyncpg.py:65: in call
    query = self.get_query(method, args)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <elasticapm.instrumentation.packages.asyncio.asyncpg.AsyncPGInstrumentation object at 0x7fd19d5e4b90>, method = 'Protocol.bind_execute', args = ()

    def get_query(self, method, args):
        if method in ["Protocol.query", "Protocol.copy_in", "Protocol.copy_out"]:
            return args[0]
        else:
>           return args[0].query
E           IndexError: tuple index out of range

.venv/lib/python3.11/site-packages/elasticapm/instrumentation/packages/asyncio/asyncpg.py:62: IndexError
@fritzdj
Copy link

fritzdj commented Nov 28, 2023

Related issue: elastic/apm-agent-python#1933. It looks like there is an APM agent fix coming for this.

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

No branches or pull requests

2 participants