marshmallow-code / marshmallow-code/marshmallow

TimeDelta misleading 'precision' argument & v4 breaking change

Open
#2,822 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback welcome
Dominant language
Python
Stars
7.2k
Forks
738
Avg merge
1d 23h
Merged PRs (30d)
7

Description

The docstring is correct:
> :param precision: The time unit used for (de)serialization. Must be one of 'weeks',
> 'days', 'hours', 'minutes', 'seconds', 'milliseconds' or 'microseconds'.

it's the _units_ (de)serialised to; it doesn't effect precision.

That is, 123 microseconds with the default `"seconds"` precision will serialise to `0.000123`, not `0`.

This seems to be a breaking change in v4.0.0, perhaps somehow related to the date/time/isoformat change, I think in 0c901108945573c825e33960707426c80e19290e as previously it would return a `timedelta(microseconds=123)` in the `_serialize` method, but now returns a float via `utils.timedelta_to_microseconds` divided by the 'precision''s mapping value, i.e. `1000000` for seconds.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the timedelta serialization path, including the _serialize method and utils.timedelta_to_microseconds referenced in the issue, and reproduce the 123-microsecond example with the default "seconds" setting. Compare the current behavior with the v4 change and determine what the intended precision argument semantics should be; the issue is done when the behavior and compatibility decision are covered by the relevant changes and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.