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

Support context being passed to TypeAdapter's dump_json/dump_python #9495

Merged
merged 1 commit into from
May 28, 2024

Conversation

alexcouper
Copy link
Contributor

@alexcouper alexcouper commented May 23, 2024

Change Summary

Support passing in of context to TypeAdapter's dump_python and dump_json functions, allowing context to be present during TypeAdapter serialization.

Related issue number

No related issue, but I can create one if required. Seems like this change fits into "trivial change", but I may be missing some context of my own.

Issue I'm solving for is that I want to be able to serialize an object in different contexts (using fastapi), so this piece is needed to support context based serialization of type adapters.

The upstream problem this solves (in fastapi) is illustrated here: tiangolo/fastapi#11634

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

@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label May 23, 2024
Copy link

codspeed-hq bot commented May 23, 2024

CodSpeed Performance Report

Merging #9495 will not alter performance

Comparing alexcouper:typeadapter-context (245ac01) with main (87adc65)

Summary

✅ 13 untouched benchmarks

Copy link
Member

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Amazing, thanks!

This looks great.

@sydney-runkle sydney-runkle merged commit 28b36d9 into pydantic:main May 28, 2024
52 checks passed
@alexcouper
Copy link
Contributor Author

alexcouper commented Jun 3, 2024

@sydney-runkle if I recreate this PR against 2.7 would it be accepted? Not sure the rules on if something should be in 2.8 or 2.7...

Created here: #9553 in case it's allowed

@sydney-runkle
Copy link
Member

@alexcouper,

We generally just do bug fixes in patch releases, so we'll keep this in 2.8!

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

Successfully merging this pull request may close these issues.

None yet

2 participants