8000 Error context and message by Gr1N · Pull Request #183 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c1110f0
POC of error context and message
Gr1N May 26, 2018
8a25c51
Move type errors to the `errors.py` module; Change errors interface a…
Gr1N May 27, 2018
b14c7bd
Merge branch 'master' into errors-context
Gr1N May 27, 2018
f8e4478
Rename `.as_dict()` to `.dict()`
Gr1N May 27, 2018
9692994
Fix `PydanticErrorMixin` constructor
Gr1N May 27, 2018
4ab5e69
Rename `exceptions.py` to `error_wrappers.py`
8000 Gr1N May 28, 2018
15cd4e1
Do not include nullable `ctx`
Gr1N May 28, 2018
ed6d84e
Fix tests
Gr1N May 28, 2018
9e2ed7f
Added `int_validator`; Added `IntegerError`
Gr1N May 28, 2018
6447783
Added `float_validator`; Added `FloatError`
Gr1N May 28, 2018
01a20e5
Get rid of `__mro__` in prior of `exc.code`
Gr1N May 28, 2018
ecb2ecc
Removed `min_number_size` and `max_number_size` from config (#174)
Gr1N May 28, 2018
a2cc0a9
Added `NumberMinSizeError` and `NumberMaxSizeError`
Gr1N May 28, 2018
ef07e61
Added `NoneIsNotAllowedError`
Gr1N May 28, 2018
04d72e9
Added `EnumError`
Gr1N May 29, 2018
bc3bed8
Added `path_validator`; Added `PathError`
Gr1N May 29, 2018
a677a7e
Added `DictError`
Gr1N May 30, 2018
89804fb
Added `ListError`
Gr1N May 30, 2018
9e82397
Added `TupleError`
Gr1N May 30, 2018
6c2da85
Added `SetError`
Gr1N May 30, 2018
45f49c1
Added `datetime` related errors
Gr1N May 30, 2018
95b710f
Added `bytes` and `str` related errors
Gr1N May 30, 2018
af3d24f
Added `SequenceError`
Gr1N May 30, 2018
c5c906e
Improved code coverage
Gr1N May 30, 2018
6e62458
Display error context in string representation of validation error
Gr1N May 30, 2018
9b726ee
Redefine error message templates using config
Gr1N May 30, 2018
446cc76
Review fixes
Gr1N May 31, 2018
81df1c2
Updated changelog
Gr1N May 31, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not include nullable ctx
  • Loading branch information
Gr1N committed May 28, 2018
commit 15cd4e119d0274da7695544db68239eb5335fe04
8 changes: 6 additions & 2 deletions pydantic/error_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ def type_(self):
def dict(self, *, loc_prefix=None):
loc = self.loc if loc_prefix is None else loc_prefix + self.loc

return {
d = {
'loc': loc,
'msg': self.msg,
'type': self.type_,
'ctx': self.ctx,
}

if self.ctx is not None:
d['ctx'] = self.ctx

return d


class ValidationError(ValueError):
__slots__ = 'errors', 'message'
Expand Down
34 changes: 0 additions & 34 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def test_constrained_str_too_long():
'loc': ('v',),
'msg': 'length greater than maximum allowed: 10',
'type': 'value_error',
'ctx': None,
},
]

Expand Down Expand Up @@ -79,13 +78,11 @@ def test_dsn_no_driver():
'loc': ('db_driver',),
'msg': 'None is not an allow value',
'type': 'type_error',
'ctx': None,
},
{
'loc': ('dsn',),
'msg': '"db_driver" field may not be missing or None',
'type': 'value_error',
'ctx': None,
},
]

Expand All @@ -104,7 +101,6 @@ def test_module_import():
'loc': ('module',),
'msg': '"foobar" doesn\'t look like a module path',
'type': 'value_error',
'ctx': None,
},
]

Expand Down Expand Up @@ -216,7 +212,6 @@ def test_string_too_long():
'loc': ('str_check',),
'msg': 'length greater than maximum allowed: 10',
'type': 'value_error',
'ctx': None,
},
]

Expand All @@ -229,7 +224,6 @@ def test_string_too_short():
'loc': ('str_check',),
'msg': 'length less than minimum allowed: 5',
'type': 'value_error',
'ctx': None,
},
]

Expand All @@ -251,13 +245,11 @@ def test_number_too_big():
'loc': ('int_check',),
'msg': 'size greater than maximum allowed: 10',
'type': 'value_error',
'ctx': None,
},
{
'loc': ('float_check',),
'msg': 'size greater than maximum allowed: 10',
'type': 'value_error',
'ctx': None,
},
]

Expand All @@ -270,13 +262,11 @@ def test_number_too_small():
'loc': ('int_check',),
'msg': 'size less than minimum allowed: 5',
'type': 'value_error',
'ctx': None,
},
{
'loc': ('float_check',),
'msg': 'size less than minimum allowed: 5',
'type': 'value_error',
'ctx': None,
},
]

Expand Down Expand Up @@ -314,25 +304,21 @@ def test_datetime_errors():
'loc': ('dt',),
'msg': 'month must be in 1..12',
'type': 'value_error',
'ctx': None,
},
{
'loc': ('date_',),
'msg': 'Invalid date format',
'type': 'value_error',
'ctx': None,
},
{
'loc': ('time_',),
'msg': 'hour must be in 0..23',
'type': 'value_error',
'ctx': None,
},
{
'loc': ('duration',),
'msg': 'Invalid duration format',
'type': 'value_error',
'ctx': None,
},
]

Expand Down Expand Up @@ -367,7 +353,6 @@ def test_enum_fails():
'loc': ('tool',),
'msg': '3 is not a valid ToolEnum',
'type': 'value_error',
'ctx': None,
},
]

Expand Down Expand Up @@ -422,25 +407,21 @@ class MoreStringsModel(BaseModel):
'loc': ('str_regex',),
'msg': 'string does not match regex "^xxx\\d{3}$"',
'type': 'value_err E1FE or',
'ctx': None,
},
{
'loc': ('str_min_length',),
'msg': 'length less than minimum allowed: 5',
'type': 'value_error',
'ctx': None,
},
{
'loc': ('str_email',),
'msg': 'The email address contains invalid characters before the @-sign: <.',
'type': 'value_error.email_not_valid.email_syntax',
'ctx': None,
},
{
'loc': ('name_email',),
'msg': 'The email address contains invalid characters before the @-sign: .',
'type': 'value_error.email_not_valid.email_syntax',
'ctx': None,
},
]

Expand Down Expand Up @@ -477,7 +458,6 @@ def test_dict():
'loc': ('a',),
'msg': 'value is not a valid dict, got list',
'type': 'type_error',
'ctx': None,
},
]

Expand All @@ -496,7 +476,6 @@ def test_list():
'loc': ('b',),
'msg': '\'int\' object is not iterable',
'type': 'type_error',
'ctx': None,
},
]

Expand All @@ -513,7 +492,6 @@ def test_ordered_dict():
'loc': ('c',),
'msg': '\'int\' object is not iterable',
'type': 'type_error',
'ctx': None,
},
]

Expand All @@ -533,7 +511,6 @@ def test_tuple():
'loc': ('d',),
'msg': '\'int\' object is not iterable',
'type': 'type_error',
'ctx': None,
},
]

Expand All @@ -555,19 +532,16 @@ def test_int_validation():
'loc': ('a',),
'msg': 'size less than minimum allowed: 0',
'type': 'value_error',
'ctx': None,
},
{
'loc': ('b',),
'msg': 'size greater than maximum allowed: 0',
'type': 'value_error',
'ctx': None,
},
{
'loc': ('c',),
'msg': 'size less than minimum allowed: 4',
'type': 'value_error',
'ctx': None,
},
]

Expand All @@ -589,19 +563,16 @@ def test_float_validation():
'loc': ('a',),
'msg': 'size less than minimum allowed: 0',
'type': 'value_error',
'ctx': None,
},
{
'loc': ('b',),
'msg': 'size greater than maximum allowed: 0',
'type': 'value_error',
'ctx': None,
},
{
'loc': ('c',),
'msg': 'size less than minimum allowed: 4',
'type': 'value_error',
'ctx': None,
},
]

Expand Down Expand Up @@ -640,7 +611,6 @@ class Model(BaseModel):
'loc': ('v',),
'msg': 'value is not a valid uuid',
'type': 'type_error.uuid',
'ctx': None,
},
]

Expand Down Expand Up @@ -740,7 +710,6 @@ class Config:
'loc': ('foo',),
'msg': 'size less than minimum allowed: 42.24',
'type': 'value_error',
'ctx': None,
},
]),
(condecimal(lt=Decimal('42.24')), Decimal('42'), Decimal('42')),
Expand All @@ -749,7 +718,6 @@ class Config:
'loc': ('foo',),
'msg': 'size greater than maximum allowed: 42.24',
'type': 'value_error',
'ctx': None,
},
]),
(condecimal(max_digits=2, decimal_places=2), Decimal('0.99'), Decimal('0.99')),
Expand Down Expand Up @@ -814,7 +782,6 @@ class Config:
'loc': ('foo',),
'msg': 'value is not a valid decimal',
'type': 'value_error.decimal_is_not_finite',
'ctx': None,
},
])
for value in (
Expand All @@ -828,7 +795,6 @@ class Config:
'loc': ('foo',),
'msg': 'value is not a valid decimal',
'type': 'value_error.decimal_is_not_finite',
'ctx': None,
},
])
for value in (
Expand Down
0