Support DX Duration (Timedelta) fields via a field manager - #102
Open
ramonski wants to merge 2 commits into
Open
Support DX Duration (Timedelta) fields via a field manager#102ramonski wants to merge 2 commits into
ramonski wants to merge 2 commits into
Conversation
A DX DurationField is a zope.schema Timedelta, which JSON cannot carry,
so fields like SamplePoint.sampling_frequency could not be set via the
API: a raw {days, hours, minutes} mapping went through the set<Name>
mutator and was later rejected as "wrong type".
Add a DurationFieldManager that converts a {days, hours, minutes,
seconds} mapping to/from a timedelta, register it for IDurationField,
and route duration fields through the field manager in
DexterityDataManager.set (as done for UID references).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a field manager for the DX
DurationFieldso duration values can be set and read through the JSON API.Why
senaite.core.schema.DurationFieldis azope.schema.Timedelta; its value is adatetime.timedelta, which JSON cannot represent. Setting e.g.SamplePoint.sampling_frequencyfailed:because the raw mapping went through the
setSamplingFrequencymutator unchanged and was then rejected by the field. There was no field manager registered forIDurationField, so the generic one just stored the dict.Change
DurationFieldManager(aZopeSchemaFieldManager) converts a{days, hours, minutes, seconds}mapping (or a number of minutes, or atimedelta) to atimedeltaon set, and serializes atimedeltaback to that mapping injson_data.senaite.core.schema.interfaces.IDurationField.DexterityDataManager.setroutes duration fields through the field manager (extending the same "normalizing managers bypass the raw setter" rule introduced for UID references in Normalize UID references through the field manager, not the setter #100), so the mutator does not store the dict unconverted.Testing
New
createdoctest posts a JSON body withsampling_frequency: {"days": 7}and asserts the stored value isdatetime.timedelta(7). Full suite green (31/0).Stacking
On top of #101.