Skip to content

Fix Generic Dataclass Fields Mutation Bug (when using TypeAdapter)#7435

Merged
dmontagu merged 5 commits intomainfrom
dataclass-fields-mutation-bug
Sep 14, 2023
Merged

Fix Generic Dataclass Fields Mutation Bug (when using TypeAdapter)#7435
dmontagu merged 5 commits intomainfrom
dataclass-fields-mutation-bug

Conversation

@sydney-runkle
Copy link
Copy Markdown
Contributor

@sydney-runkle sydney-runkle commented Sep 13, 2023

Change Summary

Related issue number

fix #7430

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

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Sep 13, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: aa1d4c1
Status: ✅  Deploy successful!
Preview URL: https://3e55a1f6.pydantic-docs2.pages.dev
Branch Preview URL: https://dataclass-fields-mutation-bu.pydantic-docs2.pages.dev

View logs

Comment thread pydantic/_internal/_core_utils.py Outdated
"""
origin = type_
args = args_override or ()
args = type_.__args__ if isinstance(type_, _GenericAlias) else (args_override or ()) # type: ignore
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dmontagu, could you please explain why we changed this line?

I understand the value of the deepcopy on the model's fields in _generate_schema.py, but I don't quite understand the purpose of this line here.

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.

I just noticed this misbehavior — right now, it's not producing a type ref that reflects the generic parameters like it is supposed to. In particular, this means that in principle you could get two different schemas with the same ref but that should have different parameters. I don't know why that doesn't seem to be affecting the validation behavior, but I do think this is an improvement either way.

@sydney-runkle sydney-runkle marked this pull request as ready for review September 13, 2023 19:57
@dmontagu dmontagu enabled auto-merge (squash) September 13, 2023 22:02
@dmontagu dmontagu merged commit c6e2f89 into main Sep 14, 2023
@dmontagu dmontagu deleted the dataclass-fields-mutation-bug branch September 14, 2023 03:47
@davidhewitt davidhewitt added the relnotes-fix Used for bugfixes. label Sep 21, 2023
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.

TypeAdapter fails to validate against generic dataclass when using different type parameters

3 participants