SQLAlchemy @property causes 'Unknown Field' error in Marshmallow with dump_only

后端 未结 1 1144
萌比男神i
萌比男神i 2021-01-13 15:39

I\'m using flask-marshmallow (marshmallow=v3.0.0rc1, flask-marshmallow=0.9.0) and flask-sqlalchemy (sqlalchemy=1.2.16, flask-sqlalchemy=2.3.2)

I have this model and

1条回答
  •  迷失自我
    2021-01-13 16:02

    In marshmallow 2, unknown or dump_only fields are ignored from input. Unless the user decides to add his own validation to error on them.

    In marshmallow 3, we changed that to offer three possibilities (see docs):

    • RAISE (default)
    • EXCLUDE (like marshmallow 2)
    • INCLUDE (pass data without validation)

    There's been discussions about how to deal with dump_only fields and we came to the conclusion that from client perspective, those should be treated just as unknown fields (see https://github.com/marshmallow-code/marshmallow/issues/875).

    Bottom line, your PUT payload should not include dump_only fields. Or you could set the EXCLUDE policy to your schema, but I'd favor the former option.

    0 讨论(0)
提交回复
热议问题