INNER CODE UNIT · Python
as_marshmallow_schema
Scille/umongo · src/umongo/abstract.py:52
def as_marshmallow_schema(self):
"""Return a pure-marshmallow version of this schema class"""
# Use a cache to avoid generating several times the same schema
if self._ma_schema is not None:
return self._ma_schema
# Create schema if not found in cache
nmspc = {
name: field.as_marshmallow_field() for name, field in self.fields.items()
}
name = f"Marshmallow{type(self).__name__}"
m_schema = type(name, (self.MA_BASE_SCHEMA_CLS,), nmspc)
# Add i18n support to the schema
# We can't use I18nErrorDict here because __getitem__ is not called
# when error_messages is updated with _default_error_messages.
m_schema._default_error_messages = {
k: _(v) for k, v in m_schema._default_error_messages.items()
}