Skip to content

fix: preserve FastStream schema metadata in FastAPI dependants - #2

Merged
IvanKirpichnikov merged 2 commits into
faststream-community:developfrom
dk3yyyy:fix/asyncapi-schema-metadata
Jul 30, 2026
Merged

fix: preserve FastStream schema metadata in FastAPI dependants#2
IvanKirpichnikov merged 2 commits into
faststream-community:developfrom
dk3yyyy:fix/asyncapi-schema-metadata

Conversation

@dk3yyyy

@dk3yyyy dk3yyyy commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve every native FastAPI Dependant dataclass field when extending it for FastStream
  • restore the model, custom_fields, and flat_params metadata required by FastStream schema generation
  • add a focused regression test for the FastStream metadata on FastAPI dependants

Problem

FastAPI's slotted Dependant no longer accepts the extra metadata attributes that FastStream expects when parsing handler parameters. After the compatibility update, typed subscriber schema generation reaches parse_handler_params() without a model and fails with an AssertionError.

Solution

Create a small Dependant subclass for the FastStream-specific metadata and initialize it from the native FastAPI dataclass fields that participate in initialization. This preserves FastAPI's dependency information while restoring the metadata consumed by FastStream.

Testing

  • regression test confirmed failing on unmodified develop
  • 185 non-connected tests passed on Python 3.13
  • focused regression passed with FastAPI 0.128.0 and 0.140.6 on Python 3.13
  • Ruff format and lint passed
  • codespell and typos passed
  • mypy passed across 56 files
  • Bandit and Semgrep passed with no findings
  • documentation build passed

Additional coverage

The complete non-connected suite and Rabbit in-memory integration tests passed locally. Broker-backed connected tests are covered by the repository's upstream CI matrix.

@IvanKirpichnikov

IvanKirpichnikov commented Jul 30, 2026

Copy link
Copy Markdown
Member

Hi. Thanks for the Pull Request. I'm sorry for the late feedback.

Can you please do a separate test for get_fastapi_dependant in the weekly file(e.g tests/test_get_fastapi_dependant.py ), as you did in FastStream itself and remove the test from integration with rabbit and also add the conditional if field.init to _extend_fastapi_dependant

Thank you in advance!

@dk3yyyy

dk3yyyy commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I moved the regression coverage to tests/test_get_fastapi_dependant.py, removed it from the Rabbit integration test, and added the field.init guard. The focused test and full non-connected suite pass, along with lint, mypy, security checks, and docs.

@IvanKirpichnikov
IvanKirpichnikov merged commit 62c755a into faststream-community:develop Jul 30, 2026
6 checks passed
@dk3yyyy
dk3yyyy deleted the fix/asyncapi-schema-metadata branch July 30, 2026 10:09
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.

2 participants