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

Add fallback default value for private fields in __setstate__ of BaseModel #9584

Conversation

anhpham1509
Copy link
Contributor

@anhpham1509 anhpham1509 commented Jun 6, 2024

Change Summary

  • Instead of dictionary access, it's safe to use .get for private model attributes with empty dictionary fallback value.
  • This allows compatibility to v1 BaseModel when using pickle with reference to data class as well.

Related issue number

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: @adriangb

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

codspeed-hq bot commented Jun 6, 2024

CodSpeed Performance Report

Merging #9584 will not alter performance

Comparing anhpham1509:fix/allow-backward-compatibility-with-v1-basemodel (b640268) with main (93d6015)

Summary

✅ 13 untouched benchmarks

@anhpham1509
Copy link
Contributor Author

please review

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.

This looks good to me, thank you for the fix!

@sydney-runkle sydney-runkle merged commit 8fef562 into pydantic:main Jun 6, 2024
53 checks passed
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.

3 participants