Skip to content

Conversation

anvilpete
Copy link

@anvilpete anvilpete commented Sep 7, 2025

Change Summary

This PR depends on the following PR in pydantic-core: pydantic/pydantic-core#1722.

This change adds an extra parameter to the validation functions, overriding any other model configuration.

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
)

Related issue number

feature #9278

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @DouweM

Copy link
Contributor

github-actions bot commented Oct 1, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  config.py
  main.py
  type_adapter.py
  version.py
  pydantic/plugin
  __init__.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link

codspeed-hq bot commented Oct 1, 2025

CodSpeed Performance Report

Merging #12233 will not alter performance

Comparing anvilpete:validate-extra (12c2de7) with main (05b973b)

Summary

✅ 46 untouched

@anvilpete anvilpete marked this pull request as ready for review October 1, 2025 18:26
@anvilpete
Copy link
Author

Please review. This PR requires the recent pydantic-core 2.40.0 release, so I've included the version bump and test fixes.

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 looks good to me. The pydantic-core version got bumped separately, so if you rebase on main the diff should be possible to clean up a fair bit.

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

Successfully merging this pull request may close these issues.

4 participants