Skip to content

Commit fbb1adb

Browse files
committed
fix(operator): invalid json in ferretdb
Fixed the invalid json from ferretdb system action. As per psql, see apache/openserverless#100
1 parent 8a57124 commit fbb1adb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

actions/devel/ferretdb/command/ferretbd.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@
1919
import common.util as ut
2020
import json
2121

22-
2322
from pymongo import MongoClient
2423
from common.command_data import CommandData
24+
from bson import ObjectId
25+
26+
class JSONEncoder(json.JSONEncoder):
27+
def default(self, obj):
28+
if isinstance(obj, ObjectId):
29+
return str(obj) # Convert ObjectId to string
30+
31+
return super().default(obj)
2532

2633
class FerretDB():
2734
"""
@@ -56,8 +63,9 @@ def _send_command(self,input:CommandData):
5663
db = self._get_db()
5764
response = db.command(input.get_raw_data())
5865

59-
if response:
60-
input.result(str(response))
66+
if response:
67+
json_output = json.dumps(response, cls=JSONEncoder, indent=2)
68+
input.result(json_output)
6169
input.status(200)
6270
else:
6371
input.result(f"ferretdb/mongodb operation failed")

0 commit comments

Comments
 (0)