Skip to content

Ingestion errors when a datetime object has 0 on the milliseconds #2941

Open
@joseparajelesGL

Description

@joseparajelesGL

We have a date field on ES8 with the following mapping

"date": {"type": "date"},

But we are getting a validation format

failed to parse date field [2025-03-26T20:25:00-22:00] with format [strict_date_optional_time\|\|epoch_millis]

Due to the lack of the decimal places of the seconds.
We are sending a datetime object so it's triggering this line

formatted_data = data.isoformat()
and calling .isoformat() however isoformat for datetime has a behavior that if there are not microseconds it will use the second level precision https://github.com/python/cpython/blob/95d9dea1c4ed1b1de80074b74301cee0b38d5541/Lib/_pydatetime.py#L177-L179

I can work around this by subclassing the JsonSerializer and adding an overwrite for datetimes, however is there a more permanent solution you could implement in the python client?

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