Skip to content

fix: give Route and the publisher object the options the broker takes - #3219

Merged
IvanKirpichnikov merged 3 commits into
mainfrom
test/option-surface-mirrored
Sep 23, 2026
Merged

IvanKirpichnikov merged 3 commits into
mainfrom
test/option-surface-mirrored

Conversation

@Lancetnik

@Lancetnik Lancetnik commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

The Option surface rule (#2871) says an option exists at every level it can reasonably be set. Nothing checked it: mypy over faststream/ cannot see a missing keyword — that is a call-site error, which is why tests/mypy/* exists and is written by hand.

The check

For each broker, compare the parameter names of broker.subscriber / broker.publisher against the router, the Route object and the publisher object, and assert the four results at once (tests/brokers/test_option_surface.py).

Broker.subscriber and Router.subscriber are the same registrator function (is holds for all six brokers and both methods), so those two rows cannot fail today. They stay in the assertion as a guard: the moment a router gets a signature of its own that drops an option, the test says so.

What it found, and this PR fixes

Route and the publisher objects are hand-written copies of the registrator arguments, and they were behind:

broker added to Route added to the publisher object
kafka codec, persistent autoflush, persistent
confluent codec, persistent autoflush, persistent
nats codec, persistent persistent
rabbit channel, codec, persistent persistent
redis codec, message_format, persistent message_format, persistent
mqtt codec —

codec came in with #2841 and persistent with the 0.7.0 work; both were added to the registrator and not to the objects beside it. Each parameter keeps the registrator's own type, default and docstring line, and is forwarded to it — nothing else changes.

Before this, KafkaRoute(handler, "topic", persistent=False) raised TypeError. Now it registers a non-persistent subscriber: with persistent=False the registrator keeps 0 subscribers and 0 publishers, with persistent=True it keeps 1 and 1 — the same as broker.subscriber(..., persistent=False).

Checks

The test goes red on a real regression: adding a parameter to the Kafka registrator made the Route row grow it.

mypy (1850 files), pyright (0 errors), ruff, ruff format, slotscheck, both collection gates, and the router / include-router tests of all six brokers plus this file (275 passed).

`Route` and the publisher object are written by hand next to the registrator,
so an option added to one is easy to forget in the other. The test compares
the parameter names and pins today's gaps in a table that only shrinks.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`Route` and the publisher object copy the registrator arguments by hand, so
`codec` (#2841) and `persistent` reached the registrator and not them; rabbit
also lost `channel` and redis `message_format` / `autoflush`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Lancetnik Lancetnik changed the title test: hold Route and the publisher object to the options the broker takes fix: give Route and the publisher object the options the broker takes Sep 22, 2026
@github-actions github-actions Bot added Confluent Issues related to `faststream.confluent` module AioKafka Issues related to `faststream.kafka` module NATS Issues related to `faststream.nats` module and NATS broker features Redis Issues related to `faststream.redis` module and Redis features MQTT Issues related to `faststream.mqtt` module labels Sep 22, 2026
Comment thread tests/brokers/test_option_surface.py Outdated
One small test per broker, next to its other tests, over a shared helper in
`tests/brokers/base/option_surface.py`. The classes are imported by name
instead of looked up by string, so a rename breaks the import, not the test.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@IvanKirpichnikov
IvanKirpichnikov added this pull request to the merge queue Sep 23, 2026
Merged via the queue into main with commit 6e6bb78 Sep 23, 2026
32 checks passed
@IvanKirpichnikov
IvanKirpichnikov deleted the test/option-surface-mirrored branch September 23, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AioKafka Issues related to `faststream.kafka` module Confluent Issues related to `faststream.confluent` module MQTT Issues related to `faststream.mqtt` module NATS Issues related to `faststream.nats` module and NATS broker features Redis Issues related to `faststream.redis` module and Redis features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants