Fix crash when serializing some reports to JSON #96
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.
Fixes #93
Packj will sometimes generate report data structures that cannot be serialised by the Python standard library's default JSON encoder. More specifically, these data structures will sometimes contain:
set
instances.Commit
instances.In the case of
set
, there is no equivalent JSON data structure. I have opted for a common workaround: convert theset
to a Pythonlist
, which the underlying JSON encoder will serialise as a JSON array. The difference between these two data structures is that JSON arrays are ordered whereas Pythonset
s are not. I have opted to sort the intermediary Python list prior to it being serialised. This should at least help provide more deterministic ordering.In the case of GitPython
Commit
instances, I just threw together a Pythondict
-based serialisation containing a collection of important-looking attributes. This serialisation isn't actually being used anywhere, but it could be updated to contain other things in the future.I've also removed the conditional importing of the Python
json
module, asjson
has been a part of Python's standard library for quite some time now. This allowed me to define the custom JSON encoder at load-time instead of runtime, since the custom encoder subclasses thejson
module's default one.