Skip to content

feat: validate async endpoints#849

Open
milssky wants to merge 2 commits intomasterfrom
issue-843
Open

feat: validate async endpoints#849
milssky wants to merge 2 commits intomasterfrom
issue-843

Conversation

@milssky
Copy link
Copy Markdown
Collaborator

@milssky milssky commented Apr 8, 2026

I have made things!

AI Policy

  • I have read and agree to the AI Policy, removed any "Co-Authored-By" lines attributing coding agents, and manually reviewed the final result

Checklist

  • I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made

Related issues

Closes #843

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 8, 2026

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing issue-843 (0a1b6fa) with master (bc2acba)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (bc2acba) to head (0a1b6fa).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #849   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          335       335           
  Lines        13281     13309   +28     
  Branches       414       416    +2     
=========================================
+ Hits         13281     13309   +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

if isinstance(
method,
types.FunctionType,
) and inspect.isasyncgenfunction(method):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are at it: let's all check for sync generators. Because they also won't work.

class _NoOpOptimizer(PydanticEndpointOptimizer):
@override
@classmethod
def optimize_endpoint(cls, metadata: Any) -> None: # noqa: WPS324
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, why do you need this type?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i use controller like this

    with pytest.raises(
        EndpointMetadataError,
        match='is an async generator',
    ):

        class _BadController(Controller[PydanticSerializer]):
            async def get(self) -> AsyncIterator[int]:
                yield 1  # pragma: no cover

I have pydantic error =(

.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:659: in _unknown_type_schema
    raise PydanticSchemaGenerationError(
E   pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for collections.abc.AsyncIterator[int]. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.
E
E   If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.
E
E   For further information visit https://errors.pydantic.dev/2.12/u/schema-for-unknown-type

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!

Please, then also test that SSEController an JsonLinesController do not need 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

Successfully merging this pull request may close these issues.

Validate that http endpoints can't be async generators

2 participants