-
-
Notifications
You must be signed in to change notification settings - Fork 638
Description
Maybe this is subjective, but it feels like the removal of context makes previously simple tasks much more cumbersome and verbose...
Correct my if I'm wrong, but it looks like you expect context to be completely handled outside marshmallow using basically global variables (yes, I know, contextvars are better than that, but both are similarly "loose").
For example, quite a few schemas require access to user for which the dumping happens, e.g. to filter out certain data post-dump or to include information on whether the user can do certain operations with the object being dumped. In both cases, I've been using MySchema(context={'user': session.user})
so the schema itself is agnostic to request state - any user could be passed in via the schema, not necessarily the currently logged-in user. Inside the schema it was trivial to use self.context[...]
in Method
fields or hooks.
Now, however, unless I'm missing something, ALL this functionality is gone, and I'm expected to create a new class for the context, and import it both for passing context and for receiving it (YAY for circular import issues, they were already bad enough before especially when using SQLAlchemy model schemas). It all becomes much more verbose.
A simple self.context['user']
to access it vs something like Context[UserContext].get()['user']
or Context[UserContext].get()
(haven't actually tested v4 yet, so not sure how exactly it works).
And honestly, I'm absolutely not looking forward to fixing over 50 occurrences of self.context
plus roughly the same number of places where it's being passed to a schema...
The description of #2707 still mentions that "Context can be passed in dump/load call or set in a context manager" but I can't see this in the docs nor the PR's code. So this never happened I guess?