Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flow/record/jsonpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def unpack_obj(self, obj: Any) -> RecordDescriptor | Record | Any:
del obj["_type"]
for field_type, field_name in record_descriptor.get_field_tuples():
if field_type == "bytes":
obj[field_name] = base64.b64decode(obj[field_name])
value = obj[field_name]
obj[field_name] = base64.b64decode(value) if value is not None else None
return record_descriptor.recordType(**obj)
if _type == "recorddescriptor":
data = obj["_data"]
Expand Down
3 changes: 2 additions & 1 deletion tests/adapter/test_sqlite_duckdb.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems irrelevant?

Copy link
Member Author

@yunzheng yunzheng Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I noticed a deprecation warning during pytest, I was lazy to create a dedicated PR :D

I can still move it to another PR if you think that is better.

Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,12 @@ def test_read_from_sqlite(tmp_path: Path, db: Database) -> None:
"""
)
for i in range(1, 30):
dt_isoformat = datetime(2023, 10, i, 13, 37, tzinfo=timezone.utc).isoformat()
con.execute(
"""
INSERT INTO 'test/record' VALUES (?, ?, ?, ?)
""",
(f"record{i}", f"foobar{i}".encode(), datetime(2023, 10, i, 13, 37, tzinfo=timezone.utc), 3.14 + i),
(f"record{i}", f"foobar{i}".encode(), dt_isoformat, 3.14 + i),
)

# Read the SQLite database using flow.record
Expand Down
26 changes: 26 additions & 0 deletions tests/packer/test_json_packer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,29 @@ def test_record_pack_surrogateescape() -> None:

# pack the json string back to a record and make sure it is the same as before
assert packer.unpack(data) == record


def test_json_packer_bytes_type() -> None:
TestRecord = RecordDescriptor(
"test/bytes",
[
("bytes", "data"),
],
)

packer = JsonRecordPacker()

record = TestRecord(b"hello world")
data = packer.pack(record)
assert data.startswith('{"data": "aGVsbG8gd29ybGQ="')
assert packer.unpack(data) == record

record = TestRecord(data=None)
data = packer.pack(record)
assert data.startswith('{"data": null')
assert packer.unpack(data) == record

record = TestRecord(data=b"")
data = packer.pack(record)
assert data.startswith('{"data": ""')
assert packer.unpack(data) == record
Loading