Skip to content

Use AwareDateTime when generating field from DateTime(timezone=True) #407

Description

@lafrech

I didn't investigate this. I don't know if there would be an issue with this.

Basically, when I have a model with

creation_date = sqla.Column(sqla.DateTime(timezone=True), nullable=False)

I need to override the auto field in the schema

class ItemSchema(AutoSchema):
    class Meta:
        model = Item

    id = msa.auto_field(dump_only=True)
    creation_date = ma.fields.AwareDateTime(required=True)

I suppose this could be automatized.

Activity

  1. lafrech commented on Oct 3, 2026

    @lafrech
    MemberAuthor

    While we're at it, should we also use NaiveDateTime in other cases?

  2. DYNOSuprovo commented on Oct 4, 2026

    @DYNOSuprovo

    Regarding using \NaiveDateTime\ when \ imezone=False\ (or omitted):

    While symmetrical with \AwareDateTime\ for \ imezone=True, defaulting to \NaiveDateTime\ for standard \DateTime\ could be a breaking change for existing users who deserialize ISO 8601 strings with timezone offsets into standard columns (where marshmallow's default \ ields.DateTime\ previously permitted it).

    One gentle approach could be:

    1. Keep default \sa.DateTime()\ mapped to \ ields.DateTime\ for backward compatibility.
    2. If desired, support explicit opt-in or an option to map \ imezone=False\ to \ ields.NaiveDateTime\ when strict enforcement is wanted.

    Happy to adapt PR #741 if the team prefers adding \NaiveDateTime\ mapping as well!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions