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

[BUG] Does not work with anyio 4 #2081

Closed
3 tasks done
chbndrhnns opened this issue Mar 1, 2024 · 7 comments · Fixed by #2149
Closed
3 tasks done

[BUG] Does not work with anyio 4 #2081

chbndrhnns opened this issue Mar 1, 2024 · 7 comments · Fixed by #2149
Assignees
Labels
Priority: High Important but not urgent Python: ASGI ASGI integration Type: Dependency Updating or changing dependencies

Comments

@chbndrhnns
Copy link

Checklist

  • I checked the FAQ section of the documentation
  • I looked for similar issues in the issue tracker
  • I am using the latest version of Schemathesis

Describe the bug

Schemathesis does not start when anyio 4 is installed.
It seems there is a dependency on starlette-testclient which is the cause of the problem.

To Reproduce

from schemathesis import from_asgi, experimental

from starlette.applications import Starlette

schema = from_asgi("/openapi.json", Starlette())


@schema.parametrize()
def test_api(case):
    response = case.call_asgi()
    case.validate_response(response)

Expected behavior

Works

Environment

- OS: [e.g. Linux or Windows]
- Python version: [e.g. 3.11]
- Schemathesis version: [e.g. 3.20.0]
- Spec version: [e.g. Open API 3.0.2]

Additional context

../../../../../Library/Caches/pypoetry/virtualenvs/bla-Ms7_xa4C-py3.9/lib/python3.9/site-packages/starlette_testclient/_testclient.py:450: in _portal_factory
    with anyio.start_blocking_portal(**self.async_backend) as portal:
E   AttributeError: module 'anyio' has no attribute 'start_blocking_portal'
@chbndrhnns chbndrhnns added Status: Needs Triage Requires initial assessment to categorize and prioritize Type: Bug Errors or unexpected behavior labels Mar 1, 2024
@Stranger6667 Stranger6667 added Priority: High Important but not urgent Python: ASGI ASGI integration Type: Dependency Updating or changing dependencies and removed Type: Bug Errors or unexpected behavior Status: Needs Triage Requires initial assessment to categorize and prioritize labels Mar 1, 2024
@Stranger6667
Copy link
Member

Indeed, Schemathesis pins anyio to <4, exactly because of starlette-testclient

There is a plan to switch from starlette-testclient completely, but I didn't get to it just yet.

@wolfskaempf
Copy link

@Stranger6667 Is supporting anyio>=4 currently still planned (be it through switching away from starlette-testclient or some other way) and if so, can you estimate when that would be? Can I support you somehow in the migration?

@Stranger6667
Copy link
Member

Hi @wolfskaempf !

thank you for pinging. At this point I refactored the transport logic and now it should be easier to migrate that logic to httpx.

There are two main ways to get this through. The first one is to migrate ASGI transport to httpx, including sync-async bridge (the ASGI adapter in httpx is async). The other option is to add support for newer anyio versions to starlette-testclient and update it in Schemathesis.

the latter could be simpler, but I’d prefer the former one as it is cleaner and reduce our dependency on legacy tools (in a sense that starlette moved to httpx and starlette-testclient is a backport of its old code).

In terms of support I am thinking about a few ways:

  • work on the implementation, I’d be happy to assist
  • Test pre-release version when it’s ready
  • If your company uses Schemathesis, they might take a look at sponsorship options.

Other than that I am currently looking more into reworking all the jsonschema usage by integrating the next version of my ‘jsonschema’ Rust crate which aims to resolve long standing performance and compatibility issues in this area. It will take a few months, so I am not sure if I’d have the bandwidth to dive deeper into transports.

@Stranger6667
Copy link
Member

Tagging @Kludex for visibility. Maybe adjusting things on the starlette-testclient could be the easiest way to go for now.
@Kludex - would you be open to accepting anyio 4 support if I or somebody else will open a PR in the starlette-testclient repo?

@Kludex
Copy link

Kludex commented Apr 17, 2024

@Stranger6667 I gave you maintainer rights on starlette-testclient. Feel free to do what you need. 👍

@Stranger6667
Copy link
Member

@Stranger6667 I gave you maintainer rights on starlette-testclient. Feel free to do what you need. 👍

Thanks!

@Stranger6667
Copy link
Member

The fix is available in 3.27.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High Important but not urgent Python: ASGI ASGI integration Type: Dependency Updating or changing dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants