Skip to content

Commit 9650dc4

Browse files
committed
Marshalling: Disable option orjson.OPT_PASSTHROUGH_DATETIME
1 parent a6b369e commit 9650dc4

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/crate/client/http.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,17 @@ def cratedb_json_encoder(obj):
9595
Encoder function for orjson.
9696
9797
https://github.com/ijl/orjson#default
98-
https://github.com/ijl/orjson#opt_passthrough_datetime
9998
"""
100-
if isinstance(obj, (Decimal, UUID)):
99+
if isinstance(obj, (Decimal,)):
101100
return str(obj)
102-
if isinstance(obj, datetime):
103-
if obj.tzinfo is not None:
104-
delta = obj - epoch_aware
105-
else:
106-
delta = obj - epoch_naive
107-
return int(
108-
delta.microseconds / 1000.0
109-
+ (delta.seconds + delta.days * 24 * 3600) * 1000.0
110-
)
111-
if isinstance(obj, date):
112-
return calendar.timegm(obj.timetuple()) * 1000
113101
return obj
114102

115103

116104
def json_dumps(obj):
117105
return orjson.dumps(
118106
obj,
119107
default=cratedb_json_encoder,
120-
option=(orjson.OPT_PASSTHROUGH_DATETIME | orjson.OPT_SERIALIZE_NUMPY),
108+
option=orjson.OPT_SERIALIZE_NUMPY,
121109
)
122110

123111

tests/client/test_http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def test_datetime_is_converted_to_ts(self, request):
318318
# convert string to dict
319319
# because the order of the keys isn't deterministic
320320
data = json.loads(request.call_args[1]["data"])
321-
self.assertEqual(data["args"], [1425108700000])
321+
self.assertEqual(data["args"], ["2015-02-28T07:31:40"])
322322
client.close()
323323

324324
@patch(REQUEST, autospec=True)
@@ -329,7 +329,7 @@ def test_date_is_converted_to_ts(self, request):
329329
day = dt.date(2016, 4, 21)
330330
client.sql("insert into users (dt) values (?)", (day,))
331331
data = json.loads(request.call_args[1]["data"])
332-
self.assertEqual(data["args"], [1461196800000])
332+
self.assertEqual(data["args"], ["2016-04-21"])
333333
client.close()
334334

335335
def test_socket_options_contain_keepalive(self):

0 commit comments

Comments
 (0)