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

Added datetime encoder for json #61971

Open
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

abhi1693
Copy link

@abhi1693 abhi1693 commented Apr 19, 2022

What does this PR do?

What issues does this PR fix or reference?

Fixes: #59952

Previous Behavior

2022-04-19 16:07:33,385 [salt.loaded.int.netapi.rest_cherrypy.app:912 ][DEBUG   ][685855] Could not serialize the return data from Salt.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/salt/netapi/rest_cherrypy/app.py", line 908, in hypermedia_handler
    response = out(ret)
  File "/usr/lib/python3/dist-packages/salt/utils/json.py", line 137, in dumps
    return json_module.dumps(obj, **kwargs)
  File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.8/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

New Behavior

The above error is handled appropriately

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@abhi1693 abhi1693 requested a review from a team as a code owner April 19, 2022 23:26
@abhi1693 abhi1693 requested review from MKLeb and removed request for a team April 19, 2022 23:26
@welcome
Copy link

welcome bot commented Apr 19, 2022

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

@abhi1693
Copy link
Author

abhi1693 commented May 3, 2022

@MKLeb Can you please review this?

@MKLeb
Copy link
Contributor

MKLeb commented May 11, 2022

Hi @abhi1693, would you mind adding tests as well?

salt/utils/json.py Outdated Show resolved Hide resolved
@MKLeb
Copy link
Contributor

MKLeb commented Oct 25, 2022

@abhi1693 Any updates here?

@abhi1693
Copy link
Author

@MKLeb Hey sorry, I got side tracked from this. I'm on vacation this week. I'll work on this either this weekend or next Monday.

@MKLeb
Copy link
Contributor

MKLeb commented Nov 2, 2022

@abhi1693 Thanks for circling back to this one. This will just need tests and then I'll see if we can get it merged.

@abhi1693
Copy link
Author

abhi1693 commented Nov 2, 2022

I have been trying to get nox to work but it's stuck installing for last few hours

@abhi1693
Copy link
Author

abhi1693 commented Nov 9, 2022

@MKLeb I need some help with the unit tests. I have not yet made any changes and it's failing. I tried to run the unit test on the master branch and it's failing on my system.

************* Module tests.unit.utils.test_json
tests/unit/utils/test_json.py:1: [E0599(file-perms), ] Module file has the wrong file permissions(expected 0o644): 0o664

I'm unable to figure out which module has the wrong file permissions

@MKLeb
Copy link
Contributor

MKLeb commented Nov 18, 2022

@abhi1693 I believe it is pointing to the test module, tests.unit.utils.test_json. I've had this happen to me before, a chmod with the expected perms usually does the trick.

@abhi1693
Copy link
Author

@dwoz I have changed the code to make the linter happy. It works on my local system on Linux with Python 3.10

@abhi1693
Copy link
Author

abhi1693 commented Jan 7, 2024

@s0undt3ch and @dwoz I have made all changes, can this be reviewed and merged now?

@abhi1693
Copy link
Author

abhi1693 commented Feb 7, 2024

@s0undt3ch @dwoz Can you please review this?

@abhi1693
Copy link
Author

@dwoz @s0undt3ch Guys, it's been 2 years and it's an incredibly small change. I have done everything that's been asked but this review process is incredibly slow to get past. If it's not going to be merged, let me know. I'll look for alternatives like Ansible because we are stuck on a very old release due to this bug

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.

[BUG] Salt API fails to encode datetime objects as JSON.
5 participants