Skip to content

fix (fastapi): skip init=False fields when copying Dependant - #2966

Merged
borisalekseev merged 6 commits into
mainfrom
fix/fastapi-compat
Jul 29, 2026
Merged

fix (fastapi): skip init=False fields when copying Dependant#2966
borisalekseev merged 6 commits into
mainfrom
fix/fastapi-compat

Conversation

@Lancetnik

@Lancetnik Lancetnik commented Jul 29, 2026

Copy link
Copy Markdown
Member

Description

Three related changes on this branch.

fix (fastapi) — skip init=False fields when copying FastAPI's Dependant. Newer FastAPI versions mark some Dependant fields init=False, so passing them to the constructor raises.

chore(tests) — group the Redis cluster and sentinel tests into tests/brokers/redis/cluster/ and tests/brokers/redis/sentinel/ subpackages.

chore(tests) — stop importing from conftest.py modules. pytest loads conftest modules specially, so a direct import (from .conftest import Settings) can yield a duplicated/mismatched module and confusing collection errors. Each broker's Settings dataclass now lives in a plain settings.py helper imported by both the conftest and the test files. SettingsCluster and the settings_cluster fixture moved down into tests/brokers/redis/cluster/, their only users. The rule is documented in the testing-patterns skill.

Type of change

  • Bug fix (a non-breaking change that resolves an issue)

Checklist

  • My code adheres to the style guidelines of this project (just lint shows no errors)
  • I have conducted a self-review of my own code
  • My changes do not generate any new warnings
  • I have ensured that static analysis tests are passing by running just static-analysis
  • Both new and existing unit tests pass successfully on my local environment by running just test-coveragetests/brokers/redis passes (624 passed, 2 skipped, 1 xfailed) and the connected suites collect cleanly, but the full coverage run was not executed locally

Lancetnik and others added 3 commits July 29, 2026 20:28
Dataclass fields declared with `field(init=False)` cannot be passed to
the constructor, so building `_FastStreamDependant` from a parent
`Dependant` that has any such field raised a TypeError.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Move tests/brokers/redis/test_cluster*.py into tests/brokers/redis/cluster/
and test_sentinel.py into tests/brokers/redis/sentinel/. Also bump the
project version to 0.7.3 in uv.lock.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Importing from a conftest.py is unsafe: pytest loads conftest modules
specially, so a direct import can yield a duplicated/mismatched module.
Declare the Settings dataclasses in plain settings.py helpers next to
each broker's tests and import them from both the conftest and the test
files.

Also move SettingsCluster and the settings_cluster fixture down into
tests/brokers/redis/cluster/, where they are the only users.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Lancetnik
Lancetnik requested a review from borisalekseev as a code owner July 29, 2026 17:56
Lancetnik and others added 3 commits July 29, 2026 20:57
The kafka and confluent test_batch_body.py modules were identical modulo
naming: 500 lines whose only real differences were the import aliases and
`m.key` vs `m.key()`. Worse, the confluent module imported
`faststream.kafka.response` for its non-async tests, so confluent's own
`batch_bodies` setter had no unit coverage at all.

Move the shared cases into a `BatchKeysTestcase` in tests/brokers/base,
driven by a single `KEY_ALIGNMENT_CASES` table, and leave each broker a
thin subclass supplying its own classes and key accessor.

Keep only the e2e test: `key_for()` is reached through the TestBroker
batch publish path, so the middleware test covers the setter, _align_keys
and key_for as a superset of what the unit test checked.

Also drop `test_random_bodies` -- same inputs as `test_keys_order` with a
membership assertion too weak to catch a mis-association -- folding its
unique cases in as exact-equality params, and drop the redis
`test_stream_same_group_executes_message_exactly_once` duplicate after
strengthening the remaining test to assert the payload.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@borisalekseev
borisalekseev added this pull request to the merge queue Jul 29, 2026
Merged via the queue into main with commit 3e13a04 Jul 29, 2026
30 checks passed
@borisalekseev
borisalekseev deleted the fix/fastapi-compat branch July 29, 2026 18:26
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