Repository navigation
Conversation
setPartitions stored the single valued reference sub-fields of a partition as the bare UID, where the record schema holds a list of one. Nothing could set partitions: the object was refused on validation with WrongContainedType, and the two callers that skip validation, the 2.6.0 Archetypes migration and the setup data importer, stored the bare UID, after which getPartitions read back the first character of it. Both setters also stored the partition id as a native string, where the record schema holds text. The shape a single reference is stored in belongs to the field that defines it, so to_uid_list sits beside UIDReferenceField rather than in the content type that happened to need it first. The upgrade step puts the stored records of existing templates into the types the schema holds.
|
Moved The list of one UID is how a
|
5b0d659 to
2191bad
Compare
|
Note on the overlap with #3045, which neither blocks nor is blocked by this one. The two touch the same two files in different places. #3045 changes the field types of a record ( Worth knowing while reviewing: a service record has two sub-fields written in the wrong type, and the two pull requests fix one each.
So
|
Description of the issue/feature this PR addresses
SampleTemplate.setPartitionsstores the single valued reference sub-fields of a partition as the bare UID, where the record schema holds a list of one. The sub-fields areUIDReferenceField, which derives fromzope.schema.List;getPartitionsalready knows this and reads them back with afirst()helper, since #2630.Both setters also store the partition id as a native string, where the record schema has a
TextLine.Current behavior before PR
Nothing can set partitions. The object is refused on whole-object validation:
Passing a list instead does not help, because
setPartitionsnormalises it away:The two callers that do not validate store the bare UID and keep it.
getPartitionsthen readsitems[0]off a string and hands back the first character of the UID:senaite/core/upgrade/v02_06_000.py, the Archetypes migration, which doestarget.setPartitions(src.getPartitions())senaite/core/exportimport/setupdata/__init__.py, the setup data importerSo every template that came over from Archetypes with a partition scheme has one that points at nothing, and auto-partitioning on reception uses it.
The doctest did not catch it because it only asserted the number of partitions, never a value.
Desired behavior after PR is merged
setPartitionsstores what the record schema holds: the references as a list of one UID, and the partition id as text.setServicesstores its partition id as text as well.The list of one is how a
UIDReferenceFieldstores a single reference, so the helper that builds it,to_uid_list, sits beside the field insenaite.core.schema.uidreferencefieldrather than in the content type that needed it first. It takes an object, a UID or a list of either. (api.to_listdoes not fit: it wraps a value without resolving an object to its UID, and turns an empty string into[""]where the field wants[].)The upgrade step puts the stored records of existing templates into the same shape. Base steps are untouched; only what the two callers above wrote is repaired.
Verification
The doctest now asserts the values rather than the count, and that the stored records satisfy the field:
Both fail on the current code with
FalseandWrongContainedType([WrongType('ff59...', <type 'list'>, 'sampletype')]).Checked on a running instance as well: creating a template with partitions through the JSON API now succeeds and reads back as
[{'part_id': 'part-1', 'container': ['6570d90d5e4f48789db69f58191cd86c'], 'preservation': [], 'sampletype': ['576614796c324e32af258d4431f3d312']}]Full
senaite.coretest suite: 229 tests, 0 failures, 0 errors.The other two row schemas that hold
UIDReferenceFieldsub-fields,IWorksheetLayoutSchemaandworksheettemplate.ILayoutRecord, pass their values through unchanged and are not affected.--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.