Skip to content

bug(python): nullable struct field fails with AttributeError #2654

Description

@tri2820

LanceDB version

0.24.3

What happened?

When a struct field is marked as nullable but you try to insert None for the entire struct,
LanceDB raises: AttributeError: 'pyarrow.lib.DataType' object has no attribute 'fields'

Are there known steps to reproduce?

import pyarrow as pa
import lancedb
import tempfile

# Define schema with nullable struct field
my_struct = pa.struct([pa.field("x", pa.float32())])
schema = pa.schema([
    pa.field("id", pa.string()),
    pa.field("data", my_struct).with_nullable(True)  # This is nullable
])

print(f"Field 'data' is nullable: {schema.field('data').nullable}")

with tempfile.TemporaryDirectory() as tmpdir:
    db = lancedb.connect(f"{tmpdir}/test.lancedb")
    table = db.create_table("test", schema=schema)
    
    # This works fine
    print("✓ Inserting record with struct data...")
    table.add([{"id": "1", "data": {"x": 1.0}}])
    
    # This should work (field is nullable) but fails
    print("✗ Inserting record with None data (should work but fails)...")
    table.add([{"id": "2", "data": None}])

"""
STACK TRACE:
File "lancedb/table.py", line 323, in _align_field_types
    field.type.fields,
AttributeError: 'pyarrow.lib.DataType' object has no attribute 'fields'
"""

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions