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

Consider None as return value from pre-processor rather than assume mutation #819

Merged
merged 3 commits into from May 26, 2018

Conversation

lafrech
Copy link
Member

@lafrech lafrech commented May 18, 2018

Fixes #347

TODO:

  • Update doc (incl. upgrading.rst)

assert schema.load({'value': 3}) is None
schema = PreSchema()
assert schema.dump({'value': 3}) == {}
with pytest.raises(ValidationError) as excinfo:
Copy link
Member Author

@lafrech lafrech May 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel weird about this test.

Returning None from pre_dumppre_load does not make much sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean pre_load?

Agreed that it doesn't make sense for users to do that, but I think this is the expected behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, pre_load, sorry.

The test could be catching a ValidationError for some other reason, but there is no way to narrow it without testing private interface, so we can keep it this way.

Copy link
Member

@sloria sloria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Once docs are updated, this is good to merge.

@lafrech lafrech force-pushed the dev_347_decorator_returns_none branch from e0f3813 to eba00e5 Compare May 24, 2018 22:50
@lafrech lafrech force-pushed the dev_347_decorator_returns_none branch from eba00e5 to 3b3b83a Compare May 24, 2018 22:54
@lafrech
Copy link
Member Author

lafrech commented May 24, 2018

Doc updated and PR rebased.

@lafrech lafrech changed the title WIP - Consider None as return value from pre-processor rather than assume mutation Consider None as return value from pre-processor rather than assume mutation May 24, 2018
* Clean up code for schema hooks (:issue:`814`). Thanks :user:`taion`.
* Minor performance improvement from simplifying ``utils.get_value`` (:issue:`811`). Thanks again :user:`taion`.
* Add ``require_tld`` argument to ``fields.URL`` (:issue:`749`). Thanks
- Clean up code for schema hooks (:issue:`814`). Thanks :user:`taion`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making these consistent.

In marshmallow 2.x, ``None`` returned by a pre or post-processor is interpreted as "the data was mutated". In marshmallow 3.x, the return value is considered as processed data even if it is ``None``.

Processors that mutate the data should be updated to also return it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a code example of how to update existing code, but that doesn't have to block merging of this PR.

Copy link
Member

@sloria sloria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks a lot for updating the changelog and upgrading guide.

@sloria sloria merged commit e2e2731 into dev May 26, 2018

Other changes:

- *Backwards-incompatible*: Pre/Post-processors must return modified data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in 3.0.0b12. I'll fix this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I think it got screwed up during the rebase and I didn't notice.

@lafrech lafrech deleted the dev_347_decorator_returns_none branch May 26, 2018 14:02
cript0nauta added a commit to cript0nauta/faraday that referenced this pull request Apr 22, 2019
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.

None yet

2 participants