-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
54727ff
to
fad01ed
Compare
There was a problem hiding this 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: |
There was a problem hiding this comment.
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:
appmap-python/_appmap/test/web_framework.py
Line 286 in e4b8d78
def test_can_record(self, data_dir, client): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Yes, thank you. I just canceled my review request :) |
bcbae0e
to
8efcbba
Compare
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this, please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry...
c05a6f2
to
8854f70
Compare
You are right, I forgot that you already merged the fixing part with #313. I'm changing the commit message accordingly. |
8854f70
to
90e893b
Compare
90e893b
to
61d9aee
Compare
Fixes #283.
numpy
as a dev dependency. v1.24.4 is the latest version supporting Python 3.8.tox.ini
to support differentnumpy
versions in Python 3.8 and 3.{9,10,11,12}AppMapEncoder
ensuring objects containing members withnumpy.int64
andnumpy.array
types can be serialized without errors.