Skip to content

fix(parser): make key attribute optional in Kafka model #6523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 20, 2025

Conversation

Weugene
Copy link
Contributor

@Weugene Weugene commented Apr 19, 2025

Issue number: #6508

Summary

Changes

According to Kafka documentation, key in Kafka messages is optional parameter:

In cases where no key is provided, Kafka assigns messages to partitions in a round-robin manner. However, when a key is present, Kafka ensures that all messages with the same key are routed to the same partition, preserving message order within that partition.

User experience

Please share what the user experience looks like before and after this change
Before, if I receive Kafka message without key in AWS Lambda via Apache Kafka trigger, then it broke in stage of validation of message. Now, in case of key is not provided, it will be assigned to None and it pass successfully the validation.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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.

@Weugene Weugene requested a review from a team as a code owner April 19, 2025 10:22
@boring-cyborg boring-cyborg bot added the tests label Apr 19, 2025
Copy link

boring-cyborg bot commented Apr 19, 2025

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

@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 19, 2025
@Weugene
Copy link
Contributor Author

Weugene commented Apr 19, 2025

Dear @leandrodamascena,
I have created a pull request, but don't know how to add you as a review, therefore, I tag you here.
Could you watch it?

@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 19, 2025
…w Kafka record without key into json files and added tests
@leandrodamascena leandrodamascena changed the title fix: key in Kafka records is made optional #6508 fix(parser): make key attribute optional in Kafka model Apr 19, 2025
@leandrodamascena leandrodamascena linked an issue Apr 19, 2025 that may be closed by this pull request
@github-actions github-actions bot added the bug Something isn't working label Apr 19, 2025
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Weugene thanks a lot for sending this PR to fix this issue! I see that SonarCloud is complaining about some assertions and I appreciate if you can take a look! If you can't find the issue, I can try to check it tomorrow.

btw, thanks for fixing it in event sources too,

Copy link

codecov bot commented Apr 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.16%. Comparing base (c022c09) to head (65b2586).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #6523   +/-   ##
========================================
  Coverage    96.16%   96.16%           
========================================
  Files          243      243           
  Lines        11838    11842    +4     
  Branches       885      886    +1     
========================================
+ Hits         11384    11388    +4     
  Misses         356      356           
  Partials        98       98           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Weugene added 2 commits April 20, 2025 15:15
…a record with explicit setting "key": null into kafkaEventMsk.json and kafkaEventSelfManaged.json.
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice PR @Weugene! Thanks for addressing all the comments.

APPROVED!

@leandrodamascena leandrodamascena merged commit e96e73c into aws-powertools:develop Apr 20, 2025
12 checks passed
Copy link

boring-cyborg bot commented Apr 20, 2025

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make key in Kafka event to be optional
2 participants