Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support defining marshmallow metadata on a class #231

Open
mmerickel opened this issue Oct 19, 2022 · 1 comment
Open

support defining marshmallow metadata on a class #231

mmerickel opened this issue Oct 19, 2022 · 1 comment

Comments

@mmerickel
Copy link
Collaborator

mmerickel commented Oct 19, 2022

#100 (comment) shows one workaround right now but the problem with it is that it requires defining the metadata at the location where the class is used, not where the class is defined.

It would be preferable many times to define the metadata on the class itself.

@desert.meta(unknown=marshmallow.EXCLUDE)
@dataclass
class Child:
    name: str

@dataclass
class Parent:
    name: str
    dummy_list: List[str]
    children: List[Child]

This is a lot less error prone in situations where I know that the Child schema might evolve and I want to define directly on it the intent that I don't want my deserialization to break when new fields are added.

Arguably the proposed desert.meta is ambiguous with the existing desert.metadata API so open to suggestions on naming as well...

I'm happy to contribute a PR if I can get some confidence that this will be accepted design-wise.

@archoversight
Copy link

I just ran into this bug, and putting the metadata on each call site adds a lot of additional overhead and complexity.

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

No branches or pull requests

2 participants