Repository navigation
Conversation
A NamedFile or NamedImage field on a Dexterity type that also carries a BBB set<Name> mutator was written through the mutator, which stores the value exactly as it arrives. Over the API a file arrives as base64 text, so the field ended up holding the text rather than the file, and the object then failed its own validation with "wrong type" on that field. The data manager already goes through the field manager for the managers that normalize their value. NamedFileFieldManager does precisely that: it base64-decodes the payload and builds the NamedFile or NamedImage the field is declared to hold, taking the filename and content type from the payload. It belongs in that tuple, and NamedImageFieldManager comes with it as a subclass. Laboratory.accreditation_body_logo is the case that surfaced it: a NamedBlobImage with a setAccreditationBodyLogo mutator kept from the Archetypes schema. A field without such a mutator was never affected, which is why file fields have always been settable on the types that do not carry the BBB properties.
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.
Description of the issue/feature this PR addresses
A
NamedFileorNamedImagefield on a Dexterity type that also carries a BBBset<Name>mutator is written through the mutator, which stores the value exactly as it arrives. Over the API a file arrives as base64 text, so the field ends up holding the text rather than the file, and the object then fails its own validation on that field.The data manager already goes through the field manager for the managers that normalize their value (UID references, durations, decimals).
NamedFileFieldManagerdoes precisely that: it base64-decodes the payload and builds theNamedFileorNamedImagethe field is declared to hold, taking the filename and content type from the payload. It belongs in that tuple, andNamedImageFieldManagercomes with it as a subclass.Current behavior before PR
The raw base64 string is written onto the field by
setAccreditationBodyLogo, and the following full-object validation refuses it.Desired behavior after PR is merged
The value goes through
NamedFileFieldManager, which decodes it and stores aNamedBlobImage. The file is then served as usual:Verification
accreditation_body_logoon aLaboratoryover the API with a base64 payload and afilename, and fetch it back through@@downloadand@@images.