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 Request: Specify fields that should remain required #24

Open
kevinhu opened this issue Nov 15, 2023 · 3 comments
Open

Feature Request: Specify fields that should remain required #24

kevinhu opened this issue Nov 15, 2023 · 3 comments

Comments

@kevinhu
Copy link

kevinhu commented Nov 15, 2023

Hi there, this is a really useful project! It would be great if we could pass a list of fields that should remain required in the resulting model—essentially, the opposite of the current ability to specify a subset of fields to be optional.

@asaf
Copy link

asaf commented Dec 9, 2023

Hey, maybe this is what you are looking for: https://github.com/team23/pydantic-partial/blob/main/pydantic_partial/partial.py#L22

@JensHeinrich
Copy link

I think adding an required_fields keyword argument to the *_partial_model functions and removing them here would be an even cleaner solution as often you only need a few specific fields for PATCH requests for example, but need them always

@ddanier
Copy link
Member

ddanier commented Apr 22, 2024

Current solution would be to use:

PartialModel = create_partial_model(
    Model,
    *(
        set(model_compat.model_fields.keys())
        - {"the", "fields", "you", "want", "to" "keep"}
    ),
)

Is that working for you?

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

4 participants