Update model to_json methods to use Pydantic v2 model_dump_json - #49
Update model to_json methods to use Pydantic v2 model_dump_json#49MingfengHong wants to merge 2 commits into
Conversation
…2's model_dump_json Co-authored-by: MingfengHong <76680753+MingfengHong@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request updates several Pydantic models in paperseek_core/client/models.py to use model_dump_json(by_alias=True, exclude_unset=True) instead of the older json.dumps(self.to_dict()) pattern. The reviewer pointed out that using exclude_unset=True in to_json() introduces a serialization inconsistency with to_dict(), which uses exclude_none=True. To ensure consistent behavior, it is recommended to use exclude_none=True instead.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| """Returns the JSON representation of the model using alias""" | ||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
| return json.dumps(self.to_dict()) | ||
| return self.model_dump_json(by_alias=True, exclude_unset=True) |
There was a problem hiding this comment.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
| return self.model_dump_json(by_alias=True, exclude_unset=True) | |
| return self.model_dump_json(by_alias=True, exclude_none=True) |
| """Returns the JSON representation of the model using alias""" | ||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
| return json.dumps(self.to_dict()) | ||
| return self.model_dump_json(by_alias=True, exclude_unset=True) |
There was a problem hiding this comment.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
| return self.model_dump_json(by_alias=True, exclude_unset=True) | |
| return self.model_dump_json(by_alias=True, exclude_none=True) |
| """Returns the JSON representation of the model using alias""" | ||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
| return json.dumps(self.to_dict()) | ||
| return self.model_dump_json(by_alias=True, exclude_unset=True) |
There was a problem hiding this comment.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
| return self.model_dump_json(by_alias=True, exclude_unset=True) | |
| return self.model_dump_json(by_alias=True, exclude_none=True) |
| """Returns the JSON representation of the model using alias""" | ||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
| return json.dumps(self.to_dict()) | ||
| return self.model_dump_json(by_alias=True, exclude_unset=True) |
There was a problem hiding this comment.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
| return self.model_dump_json(by_alias=True, exclude_unset=True) | |
| return self.model_dump_json(by_alias=True, exclude_none=True) |
| """Returns the JSON representation of the model using alias""" | ||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
| return json.dumps(self.to_dict()) | ||
| return self.model_dump_json(by_alias=True, exclude_unset=True) |
There was a problem hiding this comment.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
| return self.model_dump_json(by_alias=True, exclude_unset=True) | |
| return self.model_dump_json(by_alias=True, exclude_none=True) |
| """Returns the JSON representation of the model using alias""" | ||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
| return json.dumps(self.to_dict()) | ||
| return self.model_dump_json(by_alias=True, exclude_unset=True) |
There was a problem hiding this comment.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
| return self.model_dump_json(by_alias=True, exclude_unset=True) | |
| return self.model_dump_json(by_alias=True, exclude_none=True) |
| """Returns the JSON representation of the model using alias""" | ||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
| return json.dumps(self.to_dict()) | ||
| return self.model_dump_json(by_alias=True, exclude_unset=True) |
There was a problem hiding this comment.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
| return self.model_dump_json(by_alias=True, exclude_unset=True) | |
| return self.model_dump_json(by_alias=True, exclude_none=True) |
| """Returns the JSON representation of the model using alias""" | ||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
| return json.dumps(self.to_dict()) | ||
| return self.model_dump_json(by_alias=True, exclude_unset=True) |
There was a problem hiding this comment.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
| return self.model_dump_json(by_alias=True, exclude_unset=True) | |
| return self.model_dump_json(by_alias=True, exclude_none=True) |
| """Returns the JSON representation of the model using alias""" | ||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
| return json.dumps(self.to_dict()) | ||
| return self.model_dump_json(by_alias=True, exclude_unset=True) |
There was a problem hiding this comment.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
| return self.model_dump_json(by_alias=True, exclude_unset=True) | |
| return self.model_dump_json(by_alias=True, exclude_none=True) |
| """Returns the JSON representation of the model using alias""" | ||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
| return json.dumps(self.to_dict()) | ||
| return self.model_dump_json(by_alias=True, exclude_unset=True) |
There was a problem hiding this comment.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
| return self.model_dump_json(by_alias=True, exclude_unset=True) | |
| return self.model_dump_json(by_alias=True, exclude_none=True) |
|
/review |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
…2's model_dump_json Co-authored-by: MingfengHong <76680753+MingfengHong@users.noreply.github.com>
Replaced the older
json.dumps(self.to_dict())serialization logic with Pydantic v2's native and optimized.model_dump_json(by_alias=True, exclude_unset=True)across all Pydantic models inpaperseek_core/client/models.py. This resolves the inline TODOs left in the models file and improves consistency.PR created automatically by Jules for task 12731025522424327128 started by @MingfengHong