-
Notifications
You must be signed in to change notification settings - Fork 296
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When publishing a message to a Kafka topic with partition 0 explicitely set, the partition assignment is not taken into account (publishing partition is defined by the partitioner)
How to reproduce
With following code, the message should alwayx be published to partition 0, but this is not the case:
from faststream.kafka import KafkaBroker
broker = KafkaBroker("localhost:9092")
msg = {"foo": "bar"}
await broker.publish(
msg,
topic="input_data",
partition=0,
)Additional context
The problem is on the following line
| partition=partition or self.partition, |
Because 0 evaluates to False, the explicit partition assignment is not taken into account and fall backs to the default publisher partition, which is None, finally leading to use of default partitioner.
This line should be replaced with:
partition=partition if partition is not None else self.partition,
I can contribute a PR if you agree
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working