Skip to content

Conversation

seratch
Copy link
Member

@seratch seratch commented Aug 14, 2025

This pull request resolves a known issue with serialized/deserialized items.

The most common one is TypeError: cannot pickle 'pydantic_core._pydantic_core.ValidatorIterator' object with the data loaded via Pydantic methods, but we've received similar reports with other objects too.

This pull request minimizes the use of copy.deepcopy() inside this SDK to eliminate the potential runtime errors.

@seratch seratch requested a review from rm-openai August 14, 2025 07:40
@seratch seratch self-assigned this Aug 14, 2025
@seratch seratch enabled auto-merge (squash) August 14, 2025 08:08
Copy link
Collaborator

@rm-openai rm-openai left a comment

Choose a reason for hiding this comment

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

do we really need such a complex change? Can't we just replace copy.deepcopy(foo) with list(foo) to make a copy of the container?

@seratch
Copy link
Member Author

seratch commented Aug 15, 2025

@rm-openai yeah, we can simplify the implementation. I think I can remove the memo and deepcopy for basic objects and primitives. anything else you want to remove?

@rm-openai
Copy link
Collaborator

I think we don't need anything except replace all copy.deepcopy(...) with list(...)

@seratch
Copy link
Member Author

seratch commented Aug 15, 2025

@rm-openai Thanks for clarifying. Since we'd been using copy.deepcopy for union type values (str | list) and potentially we may encounter this issue with other types such as set, tuple. So, I think having this simplified common utility should be helpful for us to more easily avoid making the same mistakes in the future.

That said, if you prefer a different implementation, you can come up with your own changes. I will be happy to be a reviewer instead.

@rm-openai
Copy link
Collaborator

Yeah I think this PR is simpler: #1490. For example, it doesn't recursively copy everything in the list, because the only thing we care about is making a new top level list so that mutations dont affect the original list.

@seratch seratch closed this Aug 15, 2025
auto-merge was automatically disabled August 15, 2025 14:29

Pull request was closed

@seratch seratch deleted the safer-item-copy branch September 9, 2025 08:39
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.

2 participants