diff --git a/src/arcadedb/graph_batch.py b/src/arcadedb/graph_batch.py index dbd9ba7c..9b5cb86e 100644 --- a/src/arcadedb/graph_batch.py +++ b/src/arcadedb/graph_batch.py @@ -489,24 +489,16 @@ def new_edges( row[key] = value rows.append(row) - if not tagged: - import json - - for start in range(0, len(rows), self._BULK_CHUNK): - edge_batcher.newEdgesJson( - self._java_graph_batch, - edge_type, - json.dumps(rows[start : start + self._BULK_CHUNK]), - ) - return self - # Every chunk is written before the first one crosses, so a value the # text cannot carry (a NaN, an integer beyond 64 bits or a date-time # inside a list or map, a subnormal) can still start the per-edge - # path over with nothing buffered. + # path over with nothing buffered. The engine's JSON parser reads the + # text of a subnormal as a DECIMAL, so the untagged text is checked + # for one as well. + dumps = json_bulk_dumps_tagged if tagged else json_bulk_dumps try: texts = [ - json_bulk_dumps_tagged(rows[start : start + self._BULK_CHUNK]) + dumps(rows[start : start + self._BULK_CHUNK]) for start in range(0, len(rows), self._BULK_CHUNK) ] except (TypeError, ValueError): diff --git a/tests/test_bulk_json_paths.py b/tests/test_bulk_json_paths.py index 1c801d00..c1ca4cad 100644 --- a/tests/test_bulk_json_paths.py +++ b/tests/test_bulk_json_paths.py @@ -153,3 +153,14 @@ def test_text_that_only_looks_like_an_exponent_skips_the_subnormal_walk(monkeypa type_conversion.json_bulk_dumps([{"x": 5e-324}]) with pytest.raises(ValueError): type_conversion.json_bulk_dumps([{"x": 2.2250738585072009e-308}]) + + +@pytest.mark.parametrize("entry", ENTRY_POINTS) +@pytest.mark.parametrize("value", [5e-324, -5e-324, 1e-310]) +def test_subnormal_doubles_stay_doubles(temp_db_path, entry, value): + # the engine's JSON parser reads the text of a subnormal (5e-324) as a BigDecimal, so a bulk path that + # writes it unchecked stores a DECIMAL where every per-value path stores a double + with arcadedb.create_database(temp_db_path) as db: + _create_types(db) + (stored,) = _write(db, entry, value) + assert type(stored) is float and stored == value