docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

Flooring `since` and `until` datetime arguments down to second resolution in `container.logs`.

Open alexander-travov opened this issue 4 months ago • 0 comments

I was surprised to figure out that when you pass since and until arguments to container.logs() as datetimes they internally are floored down to the closest second with utils.datetime_to_timestamp(...).

Millisecond part of datetime is discarded.

That leads to unwanted extra logs in the output from the past before since and absent valid logs before until.

For example:

since = datetime(2025, 6, 1, hour=12, minute=0, second=0, microsecond=500_000)
logs = container.logs(since=since)
# logs would have EXTRA records in half a second from 12:00:00.000 to 12:00:00.500

until = datetime(2025, 6, 1, hour=12, minute=0, second=0, microsecond=500_000)
logs = container.logs(until=until)
# logs would NOT have records in half a second from 12:00:00.000 to 12:00:00.500

Is it by design and I need to manually convert datetime to float in such usecase?

alexander-travov avatar Jun 17 '25 16:06 alexander-travov