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: handle non json serializable types #310

Merged
merged 1 commit into from
May 28, 2024

Conversation

zermelo-wisen
Copy link
Collaborator

@zermelo-wisen zermelo-wisen commented May 23, 2024

Fixes #283.

  • Adds numpy as a dev dependency. v1.24.4 is the latest version supporting Python 3.8.
  • Changes tox.ini to support different numpy versions in Python 3.8 and 3.{9,10,11,12}
  • Adds tests for AppMapEncoder ensuring objects containing members with numpy.int64 and numpy.array types can be serialized without errors.
  • Modifies a test that generates an AppMap to cover the issue.

@zermelo-wisen zermelo-wisen force-pushed the fix/handle-non-json-serializable-types branch from 54727ff to fad01ed Compare May 23, 2024 12:56
@zermelo-wisen zermelo-wisen removed the request for review from apotterri May 23, 2024 13:01
Copy link
Collaborator

@apotterri apotterri left a comment

Choose a reason for hiding this comment

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

One additional test to add. Also, the build is red, but maybe you already noticed that?

@@ -48,3 +53,18 @@ def check_comment(self, to_dict):
return ret

verify_example_appmap(check_comment, "instance_method")

class TestAppMapEncoder:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is good. I think it would also be helpful, especially to understand the impact of the change, to update one of the tests that actually generates an AppMap. One of these two could be good:

def test_can_record(self, data_dir, client):
, or https://github.com/getappmap/appmap-python/blob/master/_appmap/test/test_test_frameworks.py#L94

Copy link
Collaborator Author

@zermelo-wisen zermelo-wisen May 23, 2024

Choose a reason for hiding this comment

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

Actually, I tried to create exactly this as a separate AppMap generation test but wasn't able to produce the expected error - test passes without the fix as well. Returning int64 typed values from or accepting them as arguments to recorded functions seems not to produce the error.

Here is a temp branch if you want to take a look at what am I missing there: https://github.com/getappmap/appmap-python/tree/temp/test-recording-with-numpy-int64

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's hard to tell why this isn't reproducing the expected behavior, because it's only checking the length of the event array.

The reason I picked those other two test cases was because they'd requiring updating the expected AppMap data.

Rather than entirely new test case, can you try updating one of those tests I suggested, please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was not possible to produce a non JSON serializable AppMap by simply introducing a numpy.int64 value as an event parameter or as a return value of an event, since all values are converted to strings with event.py::display_string while encoding their container Event.

While examining the seaborn project which had this problem, it turned out that the issue occurs when numpy.int64 is used as a key in a dict that is a parameter or a return value of a recorded function. These keys become the name attributes of properties while describing the value and the schema of the return value or the parameter. The name attributes are not checked or converted to strings in event.py, which leads to this error.

In addition to the direct tests for AppMapEncoder, I modified one of the existing tests you suggested to produce the AppMap that includes the recording of a function returning a dict with numpy.int64 keys.

@zermelo-wisen
Copy link
Collaborator Author

One additional test to add. Also, the build is red, but maybe you already noticed that?

Yes, thank you. I just canceled my review request :)

@zermelo-wisen zermelo-wisen force-pushed the fix/handle-non-json-serializable-types branch 4 times, most recently from bcbae0e to 8efcbba Compare May 28, 2024 08:18
Copy link
Collaborator

@apotterri apotterri left a comment

Choose a reason for hiding this comment

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

Thanks for separating out the testing updates into a separate commit, this makes it easier to understand what you did. However, please combine them into a single commit after you remove appmap.log.

I like to use fixup! commits to accomplish this: https://git-scm.com/docs/git-commit/2.32.0#Documentation/git-commit.txt---fixupamendrewordltcommitgt .

appmap.log Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Delete this, please.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh sorry...

@zermelo-wisen zermelo-wisen force-pushed the fix/handle-non-json-serializable-types branch 2 times, most recently from c05a6f2 to 8854f70 Compare May 28, 2024 10:43
@apotterri
Copy link
Collaborator

Just want to double-check on this: #283 was fixed by #313, right? Given that there aren't any changes to how data is serialized here, seems like the commit here should be tagged test:, not fix:. We can leave the statement that it fixes #283 (since this was the final step).

@zermelo-wisen
Copy link
Collaborator Author

Just want to double-check on this: #283 was fixed by #313, right? Given that there aren't any changes to how data is serialized here, seems like the commit here should be tagged test:, not fix:. We can leave the statement that it fixes #283 (since this was the final step).

You are right, I forgot that you already merged the fixing part with #313. I'm changing the commit message accordingly.

@zermelo-wisen zermelo-wisen force-pushed the fix/handle-non-json-serializable-types branch from 8854f70 to 90e893b Compare May 28, 2024 15:07
@apotterri apotterri force-pushed the fix/handle-non-json-serializable-types branch from 90e893b to 61d9aee Compare May 28, 2024 16:22
@apotterri apotterri merged commit 99fdba2 into master May 28, 2024
1 of 2 checks passed
@apotterri apotterri deleted the fix/handle-non-json-serializable-types branch May 28, 2024 16:22
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.

Non-JSON serializable types throw an error when recorded with AppMap
2 participants