Python: recursively serialize nested container values - #7790
Conversation
|
@microsoft-github-policy-service agree |
Esan (EsanRAHIMI)
left a comment
There was a problem hiding this comment.
Thanks for the focused change—the sentinel-based recursion preserves the existing skip behavior cleanly, and the nested protocol regression coverage exercises the original failure well.
One compatibility edge is worth confirming or pinning with tests: moving the (datetime, date, time) branch into the shared helper expands conversion beyond dictionary values. Top-level date/time attributes and date/time values inside lists were previously skipped as non-serializable, but are now emitted as strings. That may be a desirable consistency fix, but it is an observable behavior change beyond nested protocol serialization. Could you either confirm it is intentional and add coverage for those locations, or restrict the conversion to the prior dictionary-value context?
|
Esan (@EsanRAHIMI) You are right; the broader date/time conversion was not intentional. Addressed in 60d9e33 by moving |
Esan (EsanRAHIMI)
left a comment
There was a problem hiding this comment.
The follow-up restores the previous date/time serialization boundary while keeping the nested container recursion intact. The regression test now covers datetime, date, and time across top-level attributes, list items, and dictionary values. This addresses my compatibility concern—thanks!
|
Evan Mattson (@moonbox3) The follow-up in 8f3b8be addresses both remaining compatibility concerns: nested non-string dictionary keys retain the previous to_dict()/to_json() behavior, and recursive list/dictionary cycles now raise the controlled ValueError while repeated acyclic references remain supported. Regression tests cover both paths, and all 507 relevant tests plus Ruff and Pyright pass locally. A fresh review of the latest commit would be appreciated when convenient. |
8f3b8be to
327aef7
Compare
|
Thanks for the suggestion! |
|
Thanks for the clarification. Updated The focused serialization tests (39 tests) and Ruff check/format pass locally. The full dependency Pyright run is currently blocked by unrelated missing optional modules in this checkout. |
|
wang ke (@CoffeeDrivenCoder) there are merge conflicts, please have a look |
e02c7b5 to
4e8b1cf
Compare
|
Resolved the merge conflicts and rebased the PR onto the latest upstream Pushed as commit |
Motivation & Context
SerializationMixin.to_dict()handled protocol objects only when they were direct list items or dictionary values. Protocol objects inside combinations such asdict -> list -> dictremained as Python objects, causing the correspondingto_json()call to fail withTypeError.Description & Review Guide
Related Issue
Fixes #7788
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.