mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
@@ -10,6 +10,7 @@ v0.10.0 (2018-XX-XX)
|
||||
* **breaking change**: removed ``Config.min_number_size`` and ``Config.max_number_size`` #183
|
||||
* added error context and ability to redefine error message templates using ``Config.error_msg_templates`` #183
|
||||
* fix typo in validator exception #150
|
||||
* copy defaults to model values, so different models don't share objects #154
|
||||
|
||||
v0.9.1 (2018-05-10)
|
||||
...................
|
||||
|
||||
+9
-6
@@ -137,6 +137,9 @@ class MetaModel(ABCMeta):
|
||||
return super().__new__(mcs, name, bases, new_namespace)
|
||||
|
||||
|
||||
_missing = object()
|
||||
|
||||
|
||||
class BaseModel(metaclass=MetaModel):
|
||||
# populated by the metaclass, defined here to help IDEs only
|
||||
__fields__ = {}
|
||||
@@ -261,18 +264,18 @@ class BaseModel(metaclass=MetaModel):
|
||||
errors = []
|
||||
|
||||
for name, field in self.__fields__.items():
|
||||
value = input_data.get(field.alias, ...)
|
||||
if value is ... and self.__config__.allow_population_by_alias and field.alt_alias:
|
||||
value = input_data.get(field.name, ...)
|
||||
value = input_data.get(field.alias, _missing)
|
||||
if value is _missing and self.__config__.allow_population_by_alias and field.alt_alias:
|
||||
value = input_data.get(field.name, _missing)
|
||||
|
||||
if value is ...:
|
||||
if value is _missing:
|
||||
if self.__config__.validate_all or field.validate_always:
|
||||
value = field.default
|
||||
value = deepcopy(field.default)
|
||||
else:
|
||||
if field.required:
|
||||
errors.append(ErrorWrapper(MissingError(), loc=field.alias, config=self.__config__))
|
||||
else:
|
||||
values[name] = field.default
|
||||
values[name] = deepcopy(field.default)
|
||||
continue
|
||||
|
||||
v_, errors_ = field.validate(value, values, loc=field.alias, cls=self.__class__)
|
||||
|
||||
+10
-1
@@ -1,5 +1,5 @@
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
from typing import Any, List
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -452,3 +452,12 @@ def test_set_tuple_values():
|
||||
assert m.foo == {'a', 'b'}
|
||||
assert m.bar == ('c', 'd')
|
||||
assert m.dict() == {'foo': {'a', 'b'}, 'bar': ('c', 'd')}
|
||||
|
||||
|
||||
def test_default_copy():
|
||||
class User(BaseModel):
|
||||
friends: List[int] = []
|
||||
|
||||
u1 = User()
|
||||
u2 = User()
|
||||
assert u1.friends is not u2.friends
|
||||
|
||||
Reference in New Issue
Block a user