Skip to content

Add extra parameter to the validate functions #1722

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anvilpete
Copy link

@anvilpete anvilpete commented May 26, 2025

Change Summary

This change adds an extra parameter to the validation functions, overriding any other model configuration. After a corresponding update to Pydantic, this will enable the following from pydantic/pydantic#9278:

SomeModel(BaseModel):
    my_field: int
    model_config = ConfigDict(extra="allow")

data = SomeModel.model_validate(
    {"myfield": 1, "extra field": 2},
    extra="forbid"  # override model config and forbid extra fields just this time
)

I've tried to add tests and update existing ones where it makes sense. It's a very small change but touches a wide surface area, so please let me know if I've missed anything.

See also pydantic/pydantic#11057 for a similar request.

Related issue number

Checklist

  • Unit tests for the changes exist
  • (N/A) Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @sydney-runkle

@anvilpete
Copy link
Author

please review

Copy link

codecov bot commented May 26, 2025

Copy link

codspeed-hq bot commented May 26, 2025

CodSpeed Performance Report

Merging #1722 will not alter performance

Comparing anvilpete:extra-override (559a3e0) with main (22d34a7)

Summary

✅ 157 untouched benchmarks

@anvilpete
Copy link
Author

anvilpete commented May 26, 2025

CI checks are failing with:

Warning: Failed to download action 'https://api.github.com/repos/dtolnay/rust-toolchain/tarball/4305c38b25d97ef35a8ad1f985ccf2d2242004f2'. Error: Response status code does not indicate success: 504 (Gateway Timeout). 
Warning: Back off 17.779 seconds before retry.
Error: Response status code does not indicate success: 504 (Gateway Timeout).

Hopefully a temporary issue. But how do I re-run them? [Edit: a force-push or two later, everything seems ok now]

@anvilpete anvilpete force-pushed the extra-override branch 3 times, most recently from bae98e8 to 74c3cd9 Compare May 26, 2025 09:46
@anvilpete
Copy link
Author

@sydney-runkle anything I can do to help get this merged?

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

Successfully merging this pull request may close these issues.

1 participant