Skip to content

Instantly share code, notes, and snippets.

@gidgid
Created October 4, 2020 08:47
Show Gist options
  • Select an option

  • Save gidgid/c2feed946d0944072aaf9fe689bf6e01 to your computer and use it in GitHub Desktop.

Select an option

Save gidgid/c2feed946d0944072aaf9fe689bf6e01 to your computer and use it in GitHub Desktop.
Pydantic hides fields starting with underscore
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