Skip to content

bug: table_names() lists table with corrupt/incomplete .lance directory that open_table() cannot open #3127

Closed

Description

@ernests

LanceDB version

0.19.0 (also present in current main — listing.rs unchanged)

What happened?

table_names() returns a table name because the .lance directory exists on disk, but open_table() fails with ValueError: Table 'conversations' was not found because the internal dataset files are missing or corrupt.

This happens when a process is interrupted between drop_table() and create_table() (e.g., during a schema migration that does drop+recreate). The result is a .lance directory with no valid manifest inside.

Root cause: ListingDatabase::table_names() (listing.rs:752) does a read_dir + filter for *.lance extensions — pure directory listing, no validation. open_table() → NativeTable::open_with_params → DatasetBuilder::from_uri().load() actually reads the manifest and fails with DatasetNotFound, which becomes TableNotFound → Python ValueError.

Code that uses the common pattern if name in db.table_names(): db.open_table(name) will fail unexpectedly.

Steps to reproduce

import lancedb
import pyarrow as pa
import shutil
import os

db = lancedb.connect("/tmp/lancedb_test")

# Create a table normally
schema = pa.schema([pa.field("id", pa.string())])
db.create_table("test_table", schema=schema)

# Simulate interrupted drop+recreate: remove internal files but keep directory
table_dir = "/tmp/lancedb_test/test_table.lance"
for item in os.listdir(table_dir):
    item_path = os.path.join(table_dir, item)
    if os.path.isdir(item_path):
        shutil.rmtree(item_path)
    else:
        os.remove(item_path)

# table_names() says it exists
print("test_table" in db.table_names(limit=100))  # True

# open_table() disagrees
db.open_table("test_table")  # ValueError: Table 'test_table' was not found

Expected behavior

Either:

  1. table_names() should validate that .lance directories contain a loadable dataset (at minimum check for _versions/ or a manifest file), or
  2. open_table() should give a distinct error (e.g., TableCorrupted) rather than TableNotFound, so callers can distinguish "never existed" from "exists but broken" and recover appropriately.

Option 2 is probably better — it's cheap and doesn't add I/O cost to table_names().

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions