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 crash when serializing some reports to JSON #96

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

KyeRussell
Copy link
Contributor

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:

  • Python set instances.
  • GitPython Commit instances.

In the case of set, there is no equivalent JSON data structure. I have opted for a common workaround: convert the set to a Python list, 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 Python sets 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 Python dict-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, as json 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 the json module's default one.

Copy link
Collaborator

@ashishbijlani ashishbijlani left a comment

Choose a reason for hiding this comment

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

Looks good.

@ashishbijlani ashishbijlani merged commit 99a6440 into ossillate-inc:main Mar 29, 2024
1 check failed
@OscarVanL
Copy link

I just encountered this on the latest docker image, which was last published 10 months ago, so doesn't include this fix. Is there any possibility a new dockerhub image could be built and pushed?

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.

Failed to dump json content to file: Object of type Commit is not JSON serializable
3 participants