Skip to content

Update model to_json methods to use Pydantic v2 model_dump_json - #49

Draft
MingfengHong wants to merge 2 commits into
mainfrom
update-document-to-json-pydantic-v2-12731025522424327128
Draft

Update model to_json methods to use Pydantic v2 model_dump_json#49
MingfengHong wants to merge 2 commits into
mainfrom
update-document-to-json-pydantic-v2-12731025522424327128

Conversation

@MingfengHong

Copy link
Copy Markdown
Owner

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 in paperseek_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

…2's model_dump_json

Co-authored-by: MingfengHong <76680753+MingfengHong@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings July 8, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

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)

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.

medium

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.

Suggested change
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)

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.

medium

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.

Suggested change
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)

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.

medium

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.

Suggested change
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)

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.

medium

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.

Suggested change
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)

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.

medium

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.

Suggested change
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)

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.

medium

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.

Suggested change
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)

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.

medium

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.

Suggested change
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)

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.

medium

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.

Suggested change
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)

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.

medium

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.

Suggested change
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)

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.

medium

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.

Suggested change
return self.model_dump_json(by_alias=True, exclude_unset=True)
return self.model_dump_json(by_alias=True, exclude_none=True)

@MingfengHong
MingfengHong marked this pull request as draft July 8, 2026 15:53
@MingfengHong

Copy link
Copy Markdown
Owner Author

/review

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

…2's model_dump_json

Co-authored-by: MingfengHong <76680753+MingfengHong@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants