Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Partial Data when Raising ModelConversionError #304

Merged
merged 1 commit into from
May 31, 2015

Conversation

edc
Copy link
Contributor

@edc edc commented May 18, 2015

Schematics already has excellent separation of data parsing and validation. This PR adds the ability to access the result of converting primitive data in case of ModelConversionError.

import_loop is the central mechanism for converting primitive values to native Python objects. If it encounters a conversion error when working on one field, the import_loop catches and stores and the error and moves on to the next field instead of bailing out completely on the first error. By the end of the import_loop, it has all the partial data parsed based on best effort in addition to all errors encountered. However, ModelConversionError only exposes the errors. This PR makes parsing result accessible as well through ModelConversionError.

Specifically, ModelConversionError is updated to have a partial_data (optional) attribute. Interested party could catch the exception and access the attribute to retrieve the parsing result. Existing code that has no interest in this attribute requires no change at all.

This feature is very handy in implementing a "best effort" parsing, which in turn is useful in building system that acts in response to user intention rather than fully validated user data. For example, in a user sign up form, the phone number field being malformed should not prevent the application from parsing the "zip code" field and auto-selects proper value for the "state" field.

kracekumar added a commit that referenced this pull request May 31, 2015
Include Partial Data when Raising ModelConversionError
@kracekumar kracekumar merged commit a0f43e1 into schematics:development May 31, 2015
@edc
Copy link
Contributor Author

edc commented Jun 1, 2015

Thanks @kracekumar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants