Created
October 4, 2020 08:47
-
-
Save gidgid/c2feed946d0944072aaf9fe689bf6e01 to your computer and use it in GitHub Desktop.
Pydantic hides fields starting with underscore
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
| from pydantic import BaseModel | |
| class Item(BaseModel): | |
| _id: str # 1 | |
| is_available: bool | |
| def test_pydantic_hides_names_with_preceding_underscores(): | |
| item = Item(_id='test-item-id', is_available=True) # 1 | |
| assert hasattr(item, '_id') is False # 2 | |
| assert item.dict().get('_id') is None # 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment