Skip to content

Commit

Permalink
Configuring PYTHON_LEGACY UUID representation in cfc_webapp.py
Browse files Browse the repository at this point in the history
We cannot encode native uuid.UUID with UuidRepresentation.UNSPECIFIED therefore defining uuid_representation as PYTHON_LEGACY fixes the issue.

Contains fix for - e-mission/e-mission-docs#856 (comment)
  • Loading branch information
swastis10 committed Mar 11, 2023
1 parent edd8b77 commit 4492edf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions emission/net/api/bottle.py
Expand Up @@ -14,8 +14,6 @@
"""

import sys
import bson.json_util as bju
from bson.binary import UuidRepresentation

__author__ = 'Marcel Hellkamp'
__version__ = '0.13-dev'
Expand Down Expand Up @@ -2003,7 +2001,7 @@ def wrapper(*a, **ka):

if isinstance(rv, dict):
#Attempt to serialize, raises exception on failure
json_response = bju.dumps(rv, json_options = bju.LEGACY_JSON_OPTIONS.with_options(uuid_representation= UuidRepresentation.PYTHON_LEGACY))
json_response = dumps(rv)
#Set content type only if serialization successful
response.content_type = 'application/json'
return json_response
Expand Down
3 changes: 2 additions & 1 deletion emission/net/api/cfc_webapp.py
Expand Up @@ -30,6 +30,7 @@
import traceback
import urllib.request, urllib.error, urllib.parse
import bson.json_util
from bson.binary import UuidRepresentation

# Our imports
import emission.net.api.visualize as visualize
Expand Down Expand Up @@ -533,7 +534,7 @@ def resolve_auth(auth_method):
for plugin in app.plugins:
if isinstance(plugin, JSONPlugin):
print("Replaced json_dumps in plugin with the one from bson")
plugin.json_dumps = bson.json_util.dumps
plugin.json_dumps = lambda s: bson.json_util.dumps(s, json_options = bson.json_util.LEGACY_JSON_OPTIONS.with_options(uuid_representation= UuidRepresentation.PYTHON_LEGACY))

print("Changing bt.json_loads from %s to %s" % (bt.json_loads, bson.json_util.loads))
bt.json_loads = bson.json_util.loads
Expand Down

0 comments on commit 4492edf

Please sign in to comment.