-
Notifications
You must be signed in to change notification settings - Fork 414
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
'async for' requires an object with __aiter__ method, got AIOTracedCursor #983
Comments
I'm going to try a fix: explicitely define |
hey @ewjoachim thanks for the report. Nice investigation, yeah, if you wanted to submit a PR what we probably need to do is add It should be something like: def __aiter__(self):
return self.__wrapped__.__aiter__() Not 100% sure if we need it to be |
Yep, I had this part alright. I'm struggling to write tests that will not SyntaxError under python versions that don't have "async for" at the moment :D |
This might help: https://github.com/DataDog/dd-trace-py/blob/master/conftest.py#L23 TL;DR; you can use folders named e.g. |
Wrapped object is an async generator, we need to explicitely define __aiter__ for this trait to be kept.
Problem
Using ddtrace and aiopg, if I do:
If my connection is not patched, I get:
(if my connection is not patched, it works)
Analysis
The cursor class is replaced with
AIOTracedCursor
which inheritswrapt.ObjectProxy
.Problem is, while thanks to
ObjectProxy
,AIOTracedCursor().__aiter__()
would most probably work and return whatever the real proxy would return, this is not enough for Python to accept that the cursor is an iterator.A small example with simple objects:
We implement
a.__iter__()
anda.__aiter__()
but Python doesn't see it:The text was updated successfully, but these errors were encountered: