From 2f6d5258022601871835a143092b6306c5b0a999 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Wed, 7 Jan 2026 12:29:45 -0800 Subject: [PATCH] fix: support `exist_ok` in `RemoteDBConnection.create_table` (#2901) RemoteDBConnection should support passing exist_ok to create_table, just like LanceDBConnection (the non-remote form) does. It can support this by passing 'exist_ok' as the mode parameter. --- python/python/lancedb/remote/db.py | 12 +++++++++ python/python/tests/test_remote_db.py | 36 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/python/python/lancedb/remote/db.py b/python/python/lancedb/remote/db.py index 6c1fb0a4c..41ec1ba3c 100644 --- a/python/python/lancedb/remote/db.py +++ b/python/python/lancedb/remote/db.py @@ -384,6 +384,7 @@ class RemoteDBConnection(DBConnection): on_bad_vectors: str = "error", fill_value: float = 0.0, mode: Optional[str] = None, + exist_ok: bool = False, embedding_functions: Optional[List[EmbeddingFunctionConfig]] = None, *, namespace: Optional[List[str]] = None, @@ -412,6 +413,12 @@ class RemoteDBConnection(DBConnection): - pyarrow.Schema - [LanceModel][lancedb.pydantic.LanceModel] + mode: str, default "create" + The mode to use when creating the table. + Can be either "create", "overwrite", or "exist_ok". + exist_ok: bool, default False + If exist_ok is True, and mode is None or "create", mode will be changed + to "exist_ok". on_bad_vectors: str, default "error" What to do if any of the vectors are not the same size or contains NaNs. One of "error", "drop", "fill". @@ -483,6 +490,11 @@ class RemoteDBConnection(DBConnection): LanceTable(table4) """ + if exist_ok: + if mode == "create": + mode = "exist_ok" + elif not mode: + mode = "exist_ok" if namespace is None: namespace = [] validate_table_name(name) diff --git a/python/python/tests/test_remote_db.py b/python/python/tests/test_remote_db.py index 759b67214..566e1fba4 100644 --- a/python/python/tests/test_remote_db.py +++ b/python/python/tests/test_remote_db.py @@ -168,6 +168,42 @@ def test_table_len_sync(): assert len(table) == 1 +def test_create_table_exist_ok(): + def handler(request): + if request.path == "/v1/table/test/create/?mode=exist_ok": + request.send_response(200) + request.send_header("Content-Type", "application/json") + request.end_headers() + request.wfile.write(b"{}") + else: + request.send_response(404) + request.end_headers() + + with mock_lancedb_connection(handler) as db: + table = db.create_table("test", [{"id": 1}], exist_ok=True) + assert table is not None + + with mock_lancedb_connection(handler) as db: + table = db.create_table("test", [{"id": 1}], mode="create", exist_ok=True) + assert table is not None + + +def test_create_table_exist_ok_with_mode_overwrite(): + def handler(request): + if request.path == "/v1/table/test/create/?mode=overwrite": + request.send_response(200) + request.send_header("Content-Type", "application/json") + request.end_headers() + request.wfile.write(b"{}") + else: + request.send_response(404) + request.end_headers() + + with mock_lancedb_connection(handler) as db: + table = db.create_table("test", [{"id": 1}], mode="overwrite", exist_ok=True) + assert table is not None + + @pytest.mark.asyncio async def test_http_error(): request_id_holder = {"request_id": None}