Skip to content

redis.scan_iter return coroutine object #944

@saber-solooki

Description

@saber-solooki

Description
I'm using scan_iter from redis library and it returns AsyncIterator in async version. Before I installed Newrelic client on my project, this piece of code was working fine:

redis = Redis.from_url("redis://localhost:6380/0")
async for found_key in redis.scan_iter(match="key"):
   some logic

I use async for since the method returns AsyncIterator. But after I installed Newrelic I got this error:

TypeError
'async for' requires an object with __aiter__ method, got coroutine

I've checked the return value of the method for both versions:
Before Newrelic:

>>> r.scan_iter(match="somekey:")
<async_generator object AsyncScanCommands.scan_iter at 0x10c95a2b0>

After installation:

>>> r.scan_iter(match="somekey:")
<coroutine object _wrap_asyncio_Redis_method_wrapper.<locals>._nr_wrapper_asyncio_Redis_async_method_ at 0x7f2957c74481>

Note that in wrapped method returns coroutine instead of async_generator. So I think there is a problem with wrapping methods from Newrelic side.

Expected Behavior
Work as before

Steps to Reproduce
Check this piece of code before and after Newrelic installation. (Your Newrelic application should be enabled of course)

import asyncio
from redis.asyncio import Redis


async def sample():
    redis = Redis.from_url("redis://localhost:6380/0")
    async for item in redis.scan_iter(match="somekey"):
        print(item)


if __name__ == '__main__':
    asyncio.run(sample())

Your Environment
newrelic==9.1.0
redis==4.6.0
python version = 3.11.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect or flawed agent behavior.needs-triageRequires initial review by maintainers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions