marshmallow-code / marshmallow-code/marshmallow
Removing Schema context feels like a bad idea!
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 738
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading issue #2707 and its referenced pull request, then compare the current v4 context documentation with the self.context examples described here. Determine whether context passed to dump/load calls or through a context manager is supported, and record the project’s intended replacement or decision for the reported migration burden.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100