Skip to content

Fix legacy serializer and deserializer warnings to be logged once - #3185

Merged
dpkp merged 1 commit into
dpkp:masterfrom
utku0dogan:fix/legacy-serializer-warning-once
Nov 6, 2026
Merged

dpkp merged 1 commit into
dpkp:masterfrom
utku0dogan:fix/legacy-serializer-warning-once

Conversation

@utku0dogan

Copy link
Copy Markdown
Contributor

Summary

In KafkaProducer._serialize and Fetcher.PartitionRecords._deserialize, the except TypeError fallback declares global _LOGGED_SERIALIZE_WARNING / global _LOGGED_DESERIALIZE_WARNING and checks the module-level flag, but assigns to LOGGED_SERIALIZE_WARNING = True / LOGGED_DESERIALIZE_WARNING = True (missing the leading underscore).

Because that creates an unused local variable instead of updating the module-level flag, the DeprecationWarning is re-evaluated and emitted on every serialized/deserialized record when using a legacy 2-argument Serializer or Deserializer subclass.

Changes

  • Update _LOGGED_SERIALIZE_WARNING in kafka/producer/kafka.py and _LOGGED_DESERIALIZE_WARNING in kafka/consumer/fetcher.py.
  • Add unit tests in test/producer/test_producer.py and test/consumer/test_fetcher.py verifying the warning is emitted once across multiple records.

@dpkp

dpkp commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Thanks!

@dpkp
dpkp merged commit f48ed14 into dpkp:master Nov 6, 2026
20 checks passed
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