marshmallow-code / marshmallow-sqlalchemy

SQLAlchemy integration with marshmallow
https://marshmallow-sqlalchemy.readthedocs.io
MIT License
557 stars 96 forks source link

nondeterministic behavior when defining custom post_load method in class inheriting SQLAlchemySchema #502

Closed beaulian closed 8 months ago

beaulian commented 1 year ago

Hi,

I found a post_load method defined in LoadInstanceMixin class called make_instance, if there exists a class inheriting SQLAlchemySchema and then I define a post_load method called f(self, data, **kwargs), it will execute before make_instance since the execution order is alphabetical according to dir builtin function. If the post_load method calls t, then it will execute after the make_instance. As a result, parameter data in function f is a dict and is an object in function g.

lafrech commented 1 year ago

Discussed a while ago in https://github.com/marshmallow-code/marshmallow/pull/600.

Since order is not enforced, if it matters, use a single processor. Here, override make_instance and add your processing in there.

beaulian commented 1 year ago

OK, thanks