Encode AT string field values to native str before validation - #101
Open
ramonski wants to merge 2 commits into
Open
Encode AT string field values to native str before validation#101ramonski wants to merge 2 commits into
ramonski wants to merge 2 commits into
Conversation
AT field validators (isEmail, isDecimal, ...) expect a native str, but values from a JSON body arrive as unicode and fail with "expected 'string'" -- so EmailAddress, Price, VAT, DuplicateVariation could not be set through the JSON API. ATFieldManager._set now utf-8-encodes text values before validation; dicts/lists/other types are left untouched, so records/datagrid/reference fields are unaffected. Adds a create doctest that posts a JSON body with a unicode decimal.
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
ATFieldManager._setnow utf-8-encodes unicode text values before the field validates them.Why
AT field validators (
isEmail,isDecimal, ...) require a nativestr. Values from a JSON request body arrive asunicode, so they failed:So
EmailAddress,Price,VAT,DuplicateVariation(and any AT field with a strict string validator) could not be set via the API. This mirrors the utf-8 handlingbika.lims.api.validatealready does on the read path.Change
Before
self.field.validate(...), encode text values withbika.lims.api.to_utf8, guarded byisinstance(value, six.text_type)so dicts/lists/numbers pass through untouched — records/datagrid/reference fields are unaffected. Nativestr(e.g. form submissions) is also untouched.Testing
New
createdoctest posts a JSON body (Price: u"12.50") and asserts the service is created withgetPrice() == '12.50'. Full suite green (31/0). The existing form-encoded doctests (nativestr) confirm no regression.Stacking
On top of #100.