Skip to content

Copy WithJsonSchema schema to avoid sharing mutated data - #11014

Merged
sydney-runkle merged 6 commits into
pydantic:mainfrom
thejcannon:patch-1
Jan 2, 2025
Merged

sydney-runkle merged 6 commits into
pydantic:mainfrom
thejcannon:patch-1

Conversation

@thejcannon

@thejcannon thejcannon commented Dec 1, 2024 •

Copy link
Copy Markdown
Contributor

Change Summary

Quick-and-simple. Just .copy() the return self.json_schema inside of WithJsonSchema so that other parts of the pipeline that modify the schema don't modify the shared object.

Related issue number

Fix #11013

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: @sydney-runkle

@github-actions github-actions Bot added the relnotes-fix Used for bugfixes. label Dec 1, 2024
@codspeed

codspeed Bot commented Dec 1, 2024 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #11014 will not alter performance

Comparing thejcannon:patch-1 (1da5638) with main (6f31f8f)

Summary

✅ 46 untouched benchmarks

@github-actions

github-actions Bot commented Dec 1, 2024

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  json_schema.py
Project Total  

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

@thejcannon
thejcannon marked this pull request as ready for review December 1, 2024 14:47
@thejcannon

Copy link
Copy Markdown
Contributor Author

please review (and thank you ❤️ )

@sydney-runkle sydney-runkle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Viicos and I discussed this. Happy to accept this fix for now. We think a shallow copy is appropriate, though if any other issues are raised related to this, we could consider a deepcopy instead.

Thanks for your contribution!

@sydney-runkle
sydney-runkle merged commit 9553fa4 into pydantic:main Jan 2, 2025
@thejcannon
thejcannon deleted the patch-1 branch January 2, 2025 17:38
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.

default added to Annotated type when WithJsonSchema is used

2 participants