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",