Skip to content

Conversation

masalim2
Copy link
Contributor

@masalim2 masalim2 commented Mar 3, 2020

Change Summary

  1. Raise TypeError in pydantic.utils.ValueItems when value is a list or tuple and the provided exclusion dict is not keyed by index.
  2. Add cautionary sentence to the Advanced include and exclude section of docs to point out correct usage of exclude in the following example.
  3. Use '__all__' keyword to exclude fields from all elements of a sequence of submodels or dicts.

Related issue number

This PR addresses a couple of my comments in #1283 -- adding a more detailed TypeError and a sentence pointing out the subtle example of correct usage. Some logic has been added to enable usage of '__all__' in the exclude kwarg of model export methods.

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)

@codecov
Copy link

codecov bot commented Mar 3, 2020

Codecov Report

Merging #1286 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1286   +/-   ##
=======================================
  Coverage   99.89%   99.89%           
=======================================
  Files          21       21           
  Lines        3713     3725   +12     
  Branches      731      736    +5     
=======================================
+ Hits         3709     3721   +12     
  Misses          2        2           
  Partials        2        2           
Impacted Files Coverage Δ
pydantic/utils.py 98.98% <100.00%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 960b24a...eb4b3af. Read the comment docs.

@masalim2 masalim2 changed the title Raise informative TypeError when passing bad exclude kwarg for list/tuple of submodels Use __all__ to exclude fields from all elements of a list/tuple of submodels. Raise more informative TypeError when passing bad exclude kwargs. Mar 6, 2020
@masalim2
Copy link
Contributor Author

Thanks for reviewing! Addressed all but the last question in the last commit.

Copy link
Member

@samuelcolvin samuelcolvin 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, I've just realised we should talk about and test fo dictionaries as well as sub-models

@masalim2
Copy link
Contributor Author

Done. Should I rebase on upstream master to resolve conflicts, or do you want to handle that yourself?

@masalim2 masalim2 force-pushed the fix-nested-export branch from 56be89a to 4d45663 Compare March 18, 2020 18:42
@samuelcolvin
Copy link
Member

I've made a few tiny tweaks to avoid wasting your time with another review. Will merge once tests pass.

@samuelcolvin samuelcolvin merged commit ebb2e6c into pydantic:master Mar 18, 2020
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