fix:Object of type time is not JSON serializable #2915
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fix: JSON serialization error for time cells in chat excel
Description
When using the chat excel feature with Excel files containing time cells (e.g., 12:30:00), a TypeError: Object of type time is not JSON serializable occurs. This issue arises because Python's time objects (generated when parsing time-formatted cells) cannot be directly serialized to JSON, disrupting the data processing workflow.
This PR resolves the problem by converting time objects to string representations before JSON serialization, ensuring seamless handling of time-formatted cells in Excel files.
Fix Details
Added type checks for time objects during Excel cell value parsing (packages/dbgpt-core/src/dbgpt/util/json_utils.py).
Testing
Tested with an Excel file containing time cells (12:30:00, 09:15:00), date cells, string cells, and numeric cells.
Verified that the chat excel feature no longer throws the JSON serialization error and correctly processes/returns time cell values as strings.
Confirmed no regression in handling other cell types (all previously functional formats remain operational).
Additional Notes
No new dependencies are introduced.
Hope this fix helps improve the chat excel functionality! Please let me know if any adjustments are needed.