-
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import numpy | ||
|
||
zero = numpy.int64(0) | ||
one = numpy.int64(1) | ||
|
||
class Simple: | ||
def hello(self): | ||
return "Hello" | ||
|
||
def world(self): | ||
return "world!" | ||
|
||
def get_non_json_serializable(self): | ||
return { zero: self.hello(), one: self.world() } | ||
|
||
def hello_world(self): | ||
return "%s %s" % (self.hello(), self.world()) | ||
result = self.get_non_json_serializable() | ||
return "%s %s" % (result[zero], result[one]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ pytest-django<4.8 | |
fastapi | ||
httpx | ||
sqlalchemy | ||
debugpy | ||
debugpy | ||
numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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
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 withevent.py::display_string
while encoding their containerEvent
.While examining the
seaborn
project which had this problem, it turned out that the issue occurs whennumpy.int64
is used as a key in adict
that is a parameter or a return value of a recorded function. These keys become thename
attributes of properties while describing the value and the schema of the return value or the parameter. Thename
attributes are not checked or converted to strings inevent.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 adict
withnumpy.int64
keys.