Skip to content
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

fix(parser): change ApproximateCreationDateTime field to datetime in DynamoDBStreamChangedRecordModel #3049

Conversation

waveFrontSet
Copy link
Contributor

Issue number: #3048

Summary

This promotes ApproximateCreationDateTime to a datetime object (instead of date) so that pydantic v2 will correctly deserialize it when parsing DynamoDB stream events.

Changes

Only the type of ApproximateCreationDateTime has changed.

User experience

If users would like to rely on a proper date object after the change, they need to use datetime's date method. Here's how that may look like.

Before the change

from aws_lambda_powertools.utilities.parser.models import DynamoDBStreamChangedRecordModel

changed_record = {
    "ApproximateCreationDateTime": 1479499740,
    "Keys": {
        "Timestamp": {"S": "2016-11-18:12:09:36"},
        "Username": {"S": "John Doe"},
    },
    "NewImage": {
        "Timestamp": {"S": "2016-11-18:12:09:36"},
        "Message": {"S": "This is a bark from the Woofer social network"},
        "Username": {"S": "John Doe"},
    },
    "SequenceNumber": "13021600000000001596893679",
    "SizeBytes": 112,
    "StreamViewType": "NEW_IMAGE",
}
model = DynamoDBStreamChangedRecordModel.model_validate(changed_record)
creation_date = model.ApproximateCreationDateTime
# Carry on with evaluating the date...

After the change

# Parse the model just like before...
creation_date = model.ApproximateCreationDateTime.date()
# Carry on with evaluating the date...

Checklist

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

Is this a breaking change? Yes, this could break existing code using Pydantic V1 that examines `ApproximateCreationDateTime` and relies on it being a proper date object.

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.

@waveFrontSet waveFrontSet requested a review from a team as a code owner September 6, 2023 13:11
@boring-cyborg boring-cyborg bot added the tests label Sep 6, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Sep 6, 2023

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/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 6, 2023
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@leandrodamascena leandrodamascena changed the title fix: promote ApproximateCreationDateTime to datetime fix(parser): promote ApproximateCreationDateTime to datetime Sep 6, 2023
@github-actions github-actions bot added the bug Something isn't working label Sep 6, 2023
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.

Approved! 😄

image

@leandrodamascena leandrodamascena changed the title fix(parser): promote ApproximateCreationDateTime to datetime fix(parser): change ApproximateCreationDateTime field to datetime Sep 6, 2023
@leandrodamascena leandrodamascena changed the title fix(parser): change ApproximateCreationDateTime field to datetime fix(parser): change ApproximateCreationDateTime field to datetime in DynamoDBStreamChangedRecordModel Sep 6, 2023
@leandrodamascena leandrodamascena merged commit 5304e5c into aws-powertools:develop Sep 6, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Sep 6, 2023

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/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests
Projects
None yet
2 participants