From 0ba70d96c392ade900f0c8ee34b9dcfdeadc4ca5 Mon Sep 17 00:00:00 2001 From: Raphael Malikian Date: Tue, 23 Jun 2026 13:42:59 -0700 Subject: [PATCH] fix: add missing stacklevel=2 to warnings.warn() and fix broken message concatenation (Fixes #3563) (#3564) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #3563 ## Summary - Add `stacklevel=2` to 10 `warnings.warn()` calls across 4 files - Fix broken message concatenation in `table.py` where the second string was incorrectly passed as the `category` parameter ## Problem Multiple `warnings.warn()` calls in the `python/lancedb/` codebase were missing the `stacklevel` parameter. Without `stacklevel=2`, warnings point to library internals instead of the caller's code, making it impossible for users to identify which of their function calls triggered the warning. Additionally, two calls in `table.py` (lines 3411 and 3420) had a more serious bug: the deprecation message was split across two separate string arguments, causing the second string to be passed as the `category` parameter instead of being concatenated with the first string. This would cause `TypeError` when the warning was triggered. ## Changes | File | Fixes | Description | |------|-------|-------------| | `embeddings/colpali.py` | 1 | Add `stacklevel=2` to `use_token_pooling` deprecation warning | | `remote/db.py` | 3 | Add `stacklevel=2` to `request_thread_pool`, `connection_timeout`, `read_timeout` deprecation warnings | | `remote/table.py` | 3 | Add `stacklevel=2` to `cleanup_old_versions`, `compact_files`, `optimize` no-op warnings | | `table.py` | 3 | Fix broken message concatenation for `data_storage_version` and `enable_v2_manifest_paths` deprecation warnings + add `stacklevel=2` to `retrain` deprecation warning | ## Verification ```python # All warnings.warn() calls now have stacklevel python3 -c "import ast, os; ..." # Result: All warnings.warn() calls now have stacklevel! ``` ## Changelog | Date | Change | Author | |------|--------|--------| | 2026-06-20 | Fix missing stacklevel=2 in 10 warnings.warn() calls + fix broken message concatenation | rtmalikian | ### Files Changed - `python/python/lancedb/embeddings/colpali.py` — Add stacklevel=2 - `python/python/lancedb/remote/db.py` — Add stacklevel=2 to 3 deprecation warnings - `python/python/lancedb/remote/table.py` — Add stacklevel=2 to 3 no-op warnings - `python/python/lancedb/table.py` — Fix broken message concatenation + add stacklevel=2 ### Verification - AST-based audit confirms all `warnings.warn()` calls now include `stacklevel=2` - Syntax check passes for all 4 modified files --- **About the Author:** Raphael Malikian — Clinical AI Solutions Architect. I specialise in building and fixing AI/ML systems for healthcare, including vector databases, RAG pipelines, and clinical NLP. If you need help with your project or think I can add value to your organisation, feel free to reach out — I'd love to connect. 📧 rtmalikian@gmail.com 🔗 GitHub: https://github.com/rtmalikian 🔗 LinkedIn: http://www.linkedin.com/in/raphael-t-malikian-mbbs-bsc-hons-71075436a --- **Disclosure:** This code was developed with assistance from **Hermes Agent** (Nous Research). All changes were reviewed, tested against the actual codebase, and verified for correctness. Signed-off-by: rtmalikian --- python/python/lancedb/embeddings/colpali.py | 1 + python/python/lancedb/remote/db.py | 3 +++ python/python/lancedb/remote/table.py | 9 ++++++--- python/python/lancedb/table.py | 7 +++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/python/python/lancedb/embeddings/colpali.py b/python/python/lancedb/embeddings/colpali.py index b2968ff0d..4b614bce3 100644 --- a/python/python/lancedb/embeddings/colpali.py +++ b/python/python/lancedb/embeddings/colpali.py @@ -81,6 +81,7 @@ class ColPaliEmbeddings(EmbeddingFunction): warnings.warn( "use_token_pooling is deprecated, use pooling_strategy=None instead", DeprecationWarning, + stacklevel=2, ) self.pooling_strategy = None diff --git a/python/python/lancedb/remote/db.py b/python/python/lancedb/remote/db.py index e57958958..201be33d5 100644 --- a/python/python/lancedb/remote/db.py +++ b/python/python/lancedb/remote/db.py @@ -124,6 +124,7 @@ class RemoteDBConnection(DBConnection): "request_thread_pool is no longer used and will be removed in " "a future release.", DeprecationWarning, + stacklevel=2, ) if connection_timeout is not None: @@ -132,6 +133,7 @@ class RemoteDBConnection(DBConnection): "release. Please use client_config.timeout_config.connect_timeout " "instead.", DeprecationWarning, + stacklevel=2, ) client_config.timeout_config.connect_timeout = timedelta( seconds=connection_timeout @@ -142,6 +144,7 @@ class RemoteDBConnection(DBConnection): "read_timeout is deprecated and will be removed in a future release. " "Please use client_config.timeout_config.read_timeout instead.", DeprecationWarning, + stacklevel=2, ) client_config.timeout_config.read_timeout = timedelta(seconds=read_timeout) diff --git a/python/python/lancedb/remote/table.py b/python/python/lancedb/remote/table.py index 5a3b5eb19..329baaa0e 100644 --- a/python/python/lancedb/remote/table.py +++ b/python/python/lancedb/remote/table.py @@ -845,7 +845,8 @@ class RemoteTable(Table): """ warnings.warn( "cleanup_old_versions() is a no-op on LanceDB Cloud. " - "Tables are automatically cleaned up and optimized." + "Tables are automatically cleaned up and optimized.", + stacklevel=2, ) pass @@ -857,7 +858,8 @@ class RemoteTable(Table): """ warnings.warn( "compact_files() is a no-op on LanceDB Cloud. " - "Tables are automatically compacted and optimized." + "Tables are automatically compacted and optimized.", + stacklevel=2, ) pass @@ -874,7 +876,8 @@ class RemoteTable(Table): """ warnings.warn( "optimize() is a no-op on LanceDB Cloud. " - "Indices are optimized automatically." + "Indices are optimized automatically.", + stacklevel=2, ) pass diff --git a/python/python/lancedb/table.py b/python/python/lancedb/table.py index 12061df49..3d4cefcb6 100644 --- a/python/python/lancedb/table.py +++ b/python/python/lancedb/table.py @@ -3409,18 +3409,20 @@ class LanceTable(Table): if data_storage_version is not None: warnings.warn( - "setting data_storage_version directly on create_table is deprecated. ", + "setting data_storage_version directly on create_table is deprecated. " "Use database_options instead.", DeprecationWarning, + stacklevel=2, ) if storage_options is None: storage_options = {} storage_options["new_table_data_storage_version"] = data_storage_version if enable_v2_manifest_paths is not None: warnings.warn( - "setting enable_v2_manifest_paths directly on create_table is ", + "setting enable_v2_manifest_paths directly on create_table is " "deprecated. Use database_options instead.", DeprecationWarning, + stacklevel=2, ) if storage_options is None: storage_options = {} @@ -5662,6 +5664,7 @@ class AsyncTable: "The 'retrain' parameter is deprecated and will be removed in a " "future version.", DeprecationWarning, + stacklevel=2, ) return await self._inner.optimize(