Skip to content

Instantly share code, notes, and snippets.

@gidgid
Last active October 4, 2020 18:38
Show Gist options
  • Save gidgid/b078233488bc67ab23351d32ad397898 to your computer and use it in GitHub Desktop.
Save gidgid/b078233488bc67ab23351d32ad397898 to your computer and use it in GitHub Desktop.
Pydantic setter doesnt validate input types
from pydantic import BaseModel
class Pizza(BaseModel):
toppings_count: int
size: str
def test_set_field_doesnt_perform_coercion():
pizza = Pizza(toppings_count='4', size='XL') # 1
assert pizza.toppings_count == 4 # 1
pizza.toppings_count = 'no coercion' # 2
assert pizza.toppings_count == 'no coercion' # 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment