Skip to content

Conversation

@utnapischtim
Copy link
Contributor

@utnapischtim utnapischtim commented Jul 26, 2025

  • marshmallow deprecated the context usage.

  • this commit introduces two ContextVars to replace the marshmallow context

needs:
inveniosoftware/invenio-access#222
inveniosoftware/marshmallow-utils#101

@utnapischtim utnapischtim marked this pull request as draft July 26, 2025 21:13
context = {**base_context}
default_identity = context["identity"] # identity required in context
def set_field_permission_check(self, context):
default_identity = context_identity.get()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is wrong, it does not use the context["identity"] as the first option, context_identity.get() should be the fallback

base_context = context or {}
context = self._build_context(base_context)
return self.schema(context=context, **schema_args).dump(data)
self.set_field_permission_check(context)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap it with a ContextManager

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        token = context_identity.set(context[identity])
        try:
            self.set_field_permission_check(context)
            return self.schema(**schema_args).dump(data)
        finally:
            context_identity.reset(None)

* marshmallow deprecated the context usage.

* this commit introduces two ContextVars to replace the marshmallow context
@utnapischtim
Copy link
Contributor Author

closed in favor of #653

if the problems should be handled independently, please update this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant