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

webgateway: use list comprehension instead of map (fix for Python 3) #245

Merged
merged 2 commits into from
Dec 16, 2020
Merged

Conversation

JonnyJD
Copy link
Contributor

@JonnyJD JonnyJD commented Dec 15, 2020

to fix JSON serialization,
as map() is an iterator in Python 3 now:
https://docs.python.org/3/library/functions.html#map

The fixed error is:

{"message": "Object of type 'map' is not JSON serializable", "stacktrace": "Traceback (most recent call last):\n  File \"/opt/omero/web/venv3/lib/python3.6/site-packages/omeroweb/webgateway/views.py\", line 1448, in wrap\n    return JsonResponse(rv, safe=safe)\n  File \"/opt/omero/web/venv3/lib/python3.6/site-packages/django/http/response.py\", line 530, in __init__\n    data = json.dumps(data, cls=encoder, **json_dumps_params)\n  File \"/usr/lib/python3.6/json/__init__.py\", line 238, in dumps\n    **kw).encode(obj)\n  File \"/usr/lib/python3.6/json/encoder.py\", line 199, in encode\n    chunks = self.iterencode(o, _one_shot=True)\n  File \"/usr/lib/python3.6/json/encoder.py\", line 257, in iterencode\n    return _iterencode(o, 0)\n  File \"/opt/omero/web/venv3/lib/python3.6/site-packages/django/core/serializers/json.py\", line 124, in default\n    return super(DjangoJSONEncoder, self).default(o)\n  File \"/usr/lib/python3.6/json/encoder.py\", line 180, in default\n    o.__class__.__name__)\nTypeError: Objec* Connection #0 to host 192.168.56.125 left intact
t of type 'map' is not JSON serializable\n"}

for example on a request like this:
/webgateway/dataset/1024/children/

It would also be possible to just wrap a list() around, but list comprehension is less complex and also used in other parts of the same file.

to fix serialization,
as map() is an iterator in Python 3 now.

The fixed error is:
Object of type 'map' is not JSON serializable
I refactored trying to leave the previous "style",
but black does not like it.
@will-moore
Copy link
Member

Fix works and code looks good. Thanks @JonnyJD.

@joshmoore joshmoore merged commit c7eb75f into ome:master Dec 16, 2020
@sbesson sbesson mentioned this pull request Dec 16, 2020
@JonnyJD JonnyJD deleted the map branch December 16, 2020 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants