Skip to content

fix(kafka): deserialize empty string record key instead of returning None - #8698

Open
ASHMEET555 wants to merge 1 commit into
aws-powertools:developfrom
ASHMEET555:fix/kafka-consumer-empty-key
Open

ASHMEET555 wants to merge 1 commit into
aws-powertools:developfrom
ASHMEET555:fix/kafka-consumer-empty-key

Conversation

@ASHMEET555

Copy link
Copy Markdown

Issue number: closes #8696

Summary

Changes

  • In ConsumerRecordRecords.key, replace truthiness check if not key: with identity check if key is None:. This ensures Kafka events with empty string keys ("key": "") are deserialized properly rather than treated as absent and returning None.
  • Align behavior with KafkaEventRecord.decoded_key in aws_lambda_powertools.utilities.data_classes.kafka_event.
  • Add functional regression test test_kafka_consumer_default_deserializer_key_is_empty_string.

User experience

  • Before: When a Kafka consumer record contained an empty string key ("key": ""), accessing record.key returned None, making it indistinguishable from a null/missing key.
  • After: Missing or None keys return None. An empty string key is preserved and deserialized (returning "" by default, or passed to the configured deserializer).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@ASHMEET555
ASHMEET555 requested a review from a team as a code owner October 28, 2026 22:04
@ASHMEET555
ASHMEET555 requested a review from hjgraca October 28, 2026 22:04
@boring-cyborg

boring-cyborg Bot commented Oct 28, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@boring-cyborg boring-cyborg Bot added the tests label Oct 28, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 28, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: ConsumerRecordRecords.key returns None when record key is an empty string

1 participant