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

[FEATURE] Use existing marshmallow schema #484

Open
FrankC01 opened this issue Sep 17, 2023 · 0 comments
Open

[FEATURE] Use existing marshmallow schema #484

FrankC01 opened this issue Sep 17, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@FrankC01
Copy link

Description

I already have (flask) Schema classes defined:

class UserIn(Schema):
    """Fields for user when requesting a new account in admin."""

    username = fields.Str(
        required=True, validate=validate.Length(min=4, max=254)
    )
    password = fields.Str(
        required=True, validate=validate.Length(min=8, max=16)
    )

I also have a dataclasses_json equivalant:

@dataclass_json
@dataclass
class InUser:
    """New user account dataclass."""

    username: str
    password: str

I want to re-use the UserIn for loading InUser. but it appears InUser.schema() does not take the already defined one?

Am I missing some subtle aspect for this?

Possible solution

No response

Alternatives

To cache the whole thing

_in_user_setup = InUser.schema(UserIn)

And deserializing from dictionary (or json)

new_user:InUser = _in_user_setup.load({...})

Context

No response

@FrankC01 FrankC01 added the enhancement New feature or request label Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant