Created
November 29, 2015 18:28
-
-
Save srossross/fba9163d1bb4c9ad92f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [14]: class Foo(Model): | |
name = StringType() | |
def __getattr__(self, attr): | |
print '__getattr__', attr | |
return self.__dict__['_initial'].get(attr, None) | |
def validate(self, partial=False, strict=False, **kwargs): | |
try: | |
super().validate(partial=partial, strict=strict, **kwargs) | |
except ModelValidationError as exc: | |
print(exc.messages) | |
....: | |
In [15]: f = Foo({'a':1, 'name':1.1}, strict=False) | |
--------------------------------------------------------------------------- | |
ModelConversionError Traceback (most recent call last) | |
<ipython-input-15-fa720cfdbb21> in <module>() | |
----> 1 f = Foo({'a':1, 'name':1.1}, strict=False) | |
/Users/sean/anaconda/envs/anaconda.org/lib/python2.7/site-packages/schematics/models.pyc in __init__(self, raw_data, deserialize_mapping, strict) | |
240 raw_data = {} | |
241 self._initial = raw_data | |
--> 242 self._data = self.convert(raw_data, strict=strict, mapping=deserialize_mapping) | |
243 | |
244 def validate(self, partial=False, strict=False): | |
/Users/sean/anaconda/envs/anaconda.org/lib/python2.7/site-packages/schematics/models.pyc in convert(self, raw_data, **kw) | |
287 The data to be converted | |
288 """ | |
--> 289 return convert(self.__class__, raw_data, **kw) | |
290 | |
291 def to_native(self, role=None, context=None): | |
/Users/sean/anaconda/envs/anaconda.org/lib/python2.7/site-packages/schematics/transforms.pyc in convert(cls, instance_or_dict, context, partial, strict, mapping) | |
417 # field_converter = lambda field, value: field.to_native(value) | |
418 data = import_loop(cls, instance_or_dict, field_converter, context=context, | |
--> 419 partial=partial, strict=strict, mapping=mapping) | |
420 return data | |
421 | |
/Users/sean/anaconda/envs/anaconda.org/lib/python2.7/site-packages/schematics/transforms.pyc in import_loop(cls, instance_or_dict, field_converter, context, partial, strict, mapping) | |
117 | |
118 if errors: | |
--> 119 raise ModelConversionError(errors, data) | |
120 | |
121 return data | |
ModelConversionError: {'name': [u"Couldn't interpret '1.1' as string."]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment