Skip to content

AsyncIterable object being forced into complete_async_iterator_value even when not in an async context #258

Closed

Description

@bellini666

Hey 👋

I'm adding support for graphql-core 3.3 on strawberry-django, and I just hit an issue, which seems to me that probably should be resolved here.

In short, for many reasons, we allow django QuerySets to be returned when resolving a list value. It also works with Django when running WSGI (sync) and ASGI (async), so we have some existing workarounds to prevent DB access inside an async context

On 3.3 there's a new check for AsyncIterable, which even solves the FIXME comment I have in the code I mentioned above. But, because QuerySet implements both __iter__ and __aiter__, it chooses the complete_async_iterator_value, even when not inside an async context, which breaks sync resolution.

I was thinking about how to workaround that on my side, and I can either force it into a list (would have some bad interaction with some query optimization we do on extensions), or wrap it into an object with only __iter__ when inside a sync-only context.

What do you think about how we can resolve this? I can see this affecting other similar Iterable+AsyncIterable, like django's QuerySet.

On strawberry, we use this in_async_context, stolen from Django's code, to decide whether to follow an async resolution path or not for those cases, and it works really well, so that's an idea

I can help write a PR for this, but let me know your thoughts first 🙏🏼

Activity

  1. bellini666 commented on Feb 1, 2026

    @bellini666
    Author

    Hi @Cito

    Any suggestions here? 🙏

  2. Cito commented on Feb 1, 2026

    @Cito
    Member

    Hi @bellini666, sorry for the late reply.

    Since we already have a configurable is_awaitable parameter in the context, I wonder whether we shouldn't just add another is_async_iterator callable? Normally it would be lambda x: isinstance(x, AsyncInterator), but it would be set to lambda x: False in graphql_sync and execute_sync, or you could also set it to some other predicate function for any other special cases.

    Would that work for you?

  3. bellini666 commented on Feb 1, 2026

    @bellini666
    Author

    Hrm, I think it works, yes! :)

    Just to be sure, are you going to do that, or should I open a PR for it? (I can, just making sure we don't do duplicated work 🤣)

  4. self-assigned this
    on Feb 1, 2026
  5. Cito commented on Feb 1, 2026

    @Cito
    Member

    I can take care of that. It's on my list for the next release now. Hopefully happening next weekend.

  6. Cito commented on Feb 15, 2026

    @Cito
    Member

    Sorry, the weekend was too short and next week is very busy. Needs to wait another week.

  7. bellini666 commented on Feb 16, 2026

    @bellini666
    Author

    @Cito np, take your time 😊

    I can also try to tackle this if you are too busy (would just need a review and a pre-release after from your hahaha)

  8. Cito commented on Feb 22, 2026

    @Cito
    Member

    @bellini666 implemented in 333d0d7 - does this work for you?

    You can install the main branch with: pip install git+https://github.com/graphql-python/graphql-core.git@main

    Will create a proper release together with some more changes next week if everything looks ok.

  9. bellini666 commented on Feb 28, 2026

    @bellini666
    Author

    Hi @Cito

    It worked! :)

    Let me know when you make a new release so I can properly finish this PR, which allows this other one on strawberry-django to be finished

  10. Cito commented on Mar 1, 2026

    @Cito
    Member

    Thank you @bellini666. Will be included in the release later this week then.

  11. Cito commented on Mar 5, 2026

    @Cito
    Member

    @bellini666 GraphQL-core 3.3.0a12 with this change is available now.

  12. bellini666 commented on Mar 7, 2026

    @bellini666
    Author

    Thank you @Cito :)

    Feel free to close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions