Skip to content

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

Merged
sydney-runkle merged 1 commit intopydantic:mainfrom
alexcouper:typeadapter-context
May 28, 2024
Merged

Support context being passed to TypeAdapter's dump_json/dump_python#9495
sydney-runkle merged 1 commit intopydantic:mainfrom
alexcouper:typeadapter-context

Conversation

@alexcouper
Copy link
Copy Markdown
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: fastapi/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
@codspeed-hq
Copy link
Copy Markdown

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
Copy Markdown
Contributor

@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
@alexcouper
Copy link
Copy Markdown
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
Copy Markdown
Contributor

@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.

2 participants