Updated dependency in my project
Before
marshmallow-sqlalchemy==0.17.0
marshmallow==3.0.0b6
After
marshmallow-sqlalchemy==0.21.0
marshmallow==3.5.0
I have such a model (simplified):
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class MyModel(Base):
__tablename__ = 'my_model'
id = Column(BigInteger, primary_key=True)
field_name = Column(String)
password = Column(String)
And schema:
from marshmallow import fields
from marshmallow_sqlalchemy import (
ModelSchema,
field_for,
)
class RegistrarSchema(ModelSchema):
class Meta:
model = MyModel
other_field_name = fields.Function(lambda obj: obj.field_name)
field_name = field_for(MyModel, 'field_name', load_from='other_field_name')
password = fields.Method("get_password")
def get_password(self, obj):
return decrypt_password(obj)
def load(self, data, session=None, instance=None, transient=False, *args, **kwargs):
if 'password' in data:
password = data['password']
instance = encrypt_password(password, instance)
return super(ModelSchema, self).load(
data, *args, session=session, instance=instance,
transient=transient, **kwargs
)
And using this code i could call
RegistrarSchema.load(data={'other_field_name': 'my_value'}, instance=instance, session=session)
and this value would be saved to field_name in my database.
After update i lost this functional - now i get
File "myfile.py", line 116, in load
transient=transient, **kwargs
File "/usr/local/lib/python3.7/dist-packages/marshmallow_sqlalchemy/schema.py", line 214, in load
return super().load(data, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/marshmallow/schema.py", line 723, in load
data, many=many, partial=partial, unknown=unknown, postprocess=True
File "/usr/local/lib/python3.7/dist-packages/marshmallow/schema.py", line 904, in _do_load
raise exc
marshmallow.exceptions.ValidationError: {'other_field_name': ['Unknown field.']}
And exaclty same error when updating password -
RegistrarSchema.load(data={'password': 'my_value'}, instance=instance, session=session)
I didnt write this code myself and cant contact developer who did it.
As i get it the goal for the first case is to give ability to write in both way -data={'my_field': 'value'}
and data={'other_field_name': 'value'}
. First scenario still working on new version, but the second not.
And in case with password - goal is to make serialization/deserialization more complex with encrypting/decrypting data.
I read update notes but was not able to find anyting specific to this issue, can someone help?