Skip to content

Instantly share code, notes, and snippets.

@gidgid
Last active November 20, 2020 13:37
Show Gist options
  • Save gidgid/ce7b7a13d91cd9424cb1e18e0f9fcd25 to your computer and use it in GitHub Desktop.
Save gidgid/ce7b7a13d91cd9424cb1e18e0f9fcd25 to your computer and use it in GitHub Desktop.
Pydantic copy doesnt perform type coercion
from pydantic import BaseModel
class Pizza(BaseModel):
toppings_count: int
size: str
def test_copy_with_update_doesnt_perform_conversion():
pizza = Pizza(toppings_count='4', size='XL') # 1
assert pizza.toppings_count == 4
new_pizza = pizza.copy(update={'toppings_count': 'not a number'}) # 2
assert new_pizza.toppings_count == 'not a number' # 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment