Skip to content

Conversation

anvilpete
Copy link
Contributor

@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
Contributor 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 (ab4e9b1) with main (e0bc980)

Summary

✅ 159 untouched benchmarks

@anvilpete
Copy link
Contributor 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 4 times, most recently from 74c3cd9 to 559a3e0 Compare May 26, 2025 09:47
@anvilpete
Copy link
Contributor Author

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

@anvilpete
Copy link
Contributor Author

@davidhewitt this has been gathering dust for a while.. anything preventing it from being merged?

Viicos
Viicos previously requested changes Aug 12, 2025
Copy link
Member

@Viicos Viicos left a comment

Choose a reason for hiding this comment

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

Sorry for the delay @anvilpete, I think this makes sense to include. Left some initial comments

@anvilpete
Copy link
Contributor Author

Thanks @Viicos, all good points. I've left my fixes unsquashed for your review.

@anvilpete
Copy link
Contributor Author

Once this is merged and released, here's the corresponding update to Pydantic: pydantic/pydantic#12233.

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, this LGTM, will merge and get in a release shortly!

@davidhewitt davidhewitt enabled auto-merge (squash) September 15, 2025 08:28
@davidhewitt davidhewitt dismissed Viicos’s stale review September 15, 2025 08:28

Changes all addressed

@davidhewitt davidhewitt merged commit b8321cc into pydantic:main Sep 15, 2025
31 checks passed
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.

3 participants