Skip to content

UTCDateTimeAttribute fails on Python's default .toisoformat() method #1297

@boompig

Description

@boompig

This is for the new changes in Pynamo 5.x which IMO makes the UTCDateTimeAttribute unusable:

https://pynamodb.readthedocs.io/en/stable/upgrading.html

No longer parsing date-time strings leniently
UTCDateTimeAttribute now strictly requires the date string format '%Y-%m-%dT%H:%M:%S.%f%z' to ensure proper ordering. PynamoDB has always written values with this format but previously would accept reading other formats. Items written using other formats must be rewritten before upgrading.

This means that strings generated using the default python from datetime import datetime, UTC; datetime.now(UTC).isoformat() will fail the validation check because the generated format looks like this:

2025-12-17T21:47:08.305464+00:00

And I have confirmed you get this error with pynamodb version 6.1.0:

ValueError: Datetime string '2025-12-17T21:47:08.305464+00:00' does not match format '%Y-%m-%dT%H:%M:%S.%f+0000'

Which means that values generated using standard python code will fail to parse with pynamo. It basically requires you to write to DynamoDB exclusively with Pynamo and never use boto3 + native python in any write applications. IMO this is a library-breaking change, with the suggested fix to just "update your values" in the database being clearly not feasible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions