Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSONDecodeError for intfstat #2739

Closed
wants to merge 1 commit into from

Conversation

ZhaohuiS
Copy link
Contributor

@ZhaohuiS ZhaohuiS commented Mar 15, 2023

What I did

Fix #14089.

PR #2636 introduced the following error if I run intfstat -c twice.
The first run is fine, because there is no intfstat tmp file, but the twice run will save new data into same tmp file again, this time, it calls json.dump(data, open(cnstat_fqn_file, 'w')) and throws traceback.

admin@str2-7050cx3-acs-01:~$ intfstat -c                    
Cleared counters
admin@str2-7050cx3-acs-01:~$ intfstat -c
Traceback (most recent call last):
  File "/usr/local/bin/intfstat", line 376, in <module>
    main()
  File "/usr/local/bin/intfstat", line 324, in main
    json.dump(data, open(cnstat_fqn_file, 'w'))
  File "/usr/lib/python3.9/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/usr/lib/python3.9/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.9/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializable

How I did it

The default value for the default parameter is None.
Should use json_serial as default format.

How to verify it

run intfstat -c twice

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@StormLiangMS
Copy link
Contributor

@qiluo-msft could you help to review?

@StormLiangMS StormLiangMS self-requested a review March 16, 2023 12:24
Copy link
Contributor

@StormLiangMS StormLiangMS left a comment

Choose a reason for hiding this comment

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

LGTM

@qiluo-msft qiluo-msft requested a review from maipbui March 17, 2023 07:20
@ZhaohuiS
Copy link
Contributor Author

#2746 will revert #2636.

@ZhaohuiS
Copy link
Contributor Author

Close it, since #2746 fixed #2739.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants