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 serialization of JSON-LD subarrays #2452

Merged
merged 1 commit into from Dec 5, 2022

Conversation

indutny
Copy link
Contributor

@indutny indutny commented Nov 26, 2022

Properties like "tag" could be lists containing multiple subclasses of ActivityObject. Make sure to serialize them recursively instead of outputting them as they are, because otherwise we could get a bunch of nulls in the resulting JSON and that wouldn't necessarily be a valid JSON-LD object.

Fix: #2451

@indutny
Copy link
Contributor Author

indutny commented Nov 26, 2022

(Disclaimer: I don't write python normally so please forgive me if this is a terrible solution of the problem and is not idiomatically correct)

@indutny
Copy link
Contributor Author

indutny commented Nov 26, 2022

My python-foo is pretty bad and I can't seem to get tests to run locally, but I think I fixed it!

@@ -194,6 +194,11 @@ def serialize(self, **kwargs):
try:
if issubclass(type(v), ActivityObject):
data[k] = v.serialize()
elif isinstance(v, list):
data[k] = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Directly nested lists are not allowed in JSON-LD, so I think we should be alright!

@indutny
Copy link
Contributor Author

indutny commented Nov 27, 2022

Yay, looks like I figured the issue with failing tests without running them 😂

@mouse-reeve
Copy link
Member

I'm seeing one issue with this -- the tag in a status with a mention goes from:

  "tag": [
    {
      "id": null,
      "type": "Mention",
      "href": "https://friend.camp/users/tripofmice",
      "name": "tripofmice@friend.camp",
      "mediaType": null,
      "attributedTo": null,
      "availability": null
    },
    ...

to

  "tag": [
    {
      "href": "https://friend.camp/users/tripofmice",
      "name": "tripofmice@friend.camp"
    },
    ...

The type field is missing. I'm not sure why!

@indutny
Copy link
Contributor Author

indutny commented Dec 5, 2022

@mouse-reeve oops! Again, I didn't get any better at Python, but I think this fix should do it. Let me know if I got it wrong!

Properties like "tag" could be lists containing multiple subclasses of
ActivityObject. Make sure to serialize them recursively instead of
outputting them as they are, because otherwise we could get a bunch of
nulls in the resulting JSON and that wouldn't necessarily be a valid
JSON-LD object.

Fix: bookwyrm-social#2451
@indutny
Copy link
Contributor Author

indutny commented Dec 5, 2022

(Lint fixed)

@mouse-reeve
Copy link
Member

Thank you for this! Seems to work just right :)

@mouse-reeve mouse-reeve merged commit 97358da into bookwyrm-social:main Dec 5, 2022
@indutny indutny deleted the fix/gh-2451 branch December 5, 2022 18:26
@indutny
Copy link
Contributor Author

indutny commented Dec 5, 2022

Hooray! Thank you!

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.

Mentioning user seems to generate invalid JSON-LD
2 participants