From c7d972fe48000ae3c91563b5f699a0e378455d0f Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Mon, 16 Nov 2026 18:56:39 +0800 Subject: [PATCH] fix(python): explain blob descriptor copy guidance (#5060) The descriptor-copy error only named the missing `data`/`uri` child. It now says that this shape is an SDK blob descriptor rather than payload bytes, and points to `blob_mode="bytes"` for supported materialization, `blob_mode="descriptions"` for inspection, and the row-id plus `fetch_blobs`/`fetch_blob_files` copy path while the source stays unchanged. This reuses the merged guidance from #4940 and the direct-materialization contract from #4973. Ray integration remains out of scope for ENT-3556. Refs ENT-3556 Test: `python/tests/test_blob.py` (210 passed, 39 skipped), including a regression that writes default lazy descriptor rows into a blob-schema table, checks the guidance, and confirms no target is created. `python/tests/test_util.py -k blob` (12 passed, 2 skipped). --- python/python/lancedb/table.py | 9 ++++++++- python/python/tests/test_blob.py | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/python/python/lancedb/table.py b/python/python/lancedb/table.py index 807edbc46..7f378a34c 100644 --- a/python/python/lancedb/table.py +++ b/python/python/lancedb/table.py @@ -1150,7 +1150,14 @@ def _align_field(field: pa.Field, target_field: pa.Field) -> pa.Field: if not any(child.name in ("data", "uri") for child in source_type): raise ValueError( f"blob struct input for column '{field.name}' must contain " - "a 'data' or 'uri' child" + "a 'data' or 'uri' child. A blob query returns an SDK " + "descriptor in this shape, and a descriptor is not payload " + "bytes. Use blob_mode='bytes' to materialize payloads, or " + "inspect descriptors with blob_mode='descriptions'. To copy " + "payloads, select row IDs with with_row_id(True), then call " + "table.fetch_blobs(column, row_ids) or " + "table.fetch_blob_files(column, row_ids). Keep the source " + "unchanged between selection and fetching." ) elif not _can_coerce_to_blob(source_type) and not isinstance( source_type, pa.ExtensionType diff --git a/python/python/tests/test_blob.py b/python/python/tests/test_blob.py index bb946c37c..f1bacb262 100644 --- a/python/python/tests/test_blob.py +++ b/python/python/tests/test_blob.py @@ -1135,6 +1135,24 @@ def test_copy_blob_subset_preserves_payloads_nulls_and_empty_values(tmp_path): assert sorted(copied, key=lambda row: row["id"]) == rows[:3] +def test_copy_blob_descriptor_rows_explains_payload_materialization(tmp_path): + db = lancedb.connect(tmp_path) + schema = pa.schema([pa.field("id", pa.int64()), lancedb.blob("image")]) + source = db.create_table("source", data=[{"id": 1, "image": b"one"}], schema=schema) + hits = source.search().where("id = 1").to_arrow() + + with pytest.raises(ValueError, match="must contain a 'data' or 'uri' child") as exc: + db.create_table("copy", data=hits, schema=schema) + + message = str(exc.value) + assert "blob_mode='bytes'" in message + assert "blob_mode='descriptions'" in message + assert "with_row_id(True)" in message + assert "fetch_blobs(column, row_ids)" in message + assert "fetch_blob_files(column, row_ids)" in message + assert not db.table_exists(["copy"]) + + def test_fetch_blobs_round_trip(): table = _blob_table( "round_trip",