Skip to content

fix(data_classes): honour a custom json_deserializer in event classes - #8884

Open
nursnaaz wants to merge 1 commit into
aws-powertools:developfrom
nursnaaz:fix/data-classes-nested-json-deserializer
Open

nursnaaz wants to merge 1 commit into
aws-powertools:developfrom
nursnaaz:fix/data-classes-nested-json-deserializer

Conversation

@nursnaaz

Copy link
Copy Markdown

Issue number: closes #8883

Summary

Changes

Five event data classes (ActiveMQEvent, KafkaEvent, RabbitMQEvent, CodePipelineJobEvent, AWSConfigRuleEvent) now accept json_deserializer in __init__ and pass it to DictWrapper. Before, passing it raised TypeError.

RabbitMQEvent, CodePipelineJobEvent, CloudWatchAlarmEvent and ConnectOutboundCampaignsEvent now pass the deserializer on to the nested objects they build.

User experience

Before: KafkaEvent(event, json_deserializer=orjson.loads) raised TypeError. For the other classes, json_data and similar properties used json.loads without notice.

After: the custom deserializer is used everywhere. Code that does not pass one behaves as before.

Verification

I added 7 unit tests that use only the public API, one in each of the existing test files. All 7 fail on develop (4 with TypeError, 3 with wrong output) and pass with this change. The tests/unit/data_classes suite passes (236 tests). The data_classes, kafka_consumer, batch, parser and event_handler suites also pass (1723 tests). ruff check, ruff format --check, mypy and ty report no problems. The change adds no new event shapes, so no AWS event was needed.

Generated by AI tools, and reviewed and verified by Mohamed Noordeen Alaudeen (@nursnaaz).


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

… that override __init__ or nest records

ActiveMQEvent, KafkaEvent, RabbitMQEvent, CodePipelineJobEvent and
AWSConfigRuleEvent override __init__ without the json_deserializer
parameter DictWrapper accepts, so passing one raised TypeError.
RabbitMQEvent, CodePipelineJobEvent, CloudWatchAlarmEvent and
ConnectOutboundCampaignsEvent also built nested wrappers without
forwarding it, so json_data / decoded_user_parameters /
reason_data_decoded / json_customer_data fell back to json.loads.
@nursnaaz
nursnaaz requested a review from a team as a code owner November 21, 2026 14:28
@boring-cyborg

boring-cyborg Bot commented Nov 21, 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 Nov 21, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 21, 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/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.

Bug: event data classes ignore a custom json_deserializer

1 participant