From 5f831bb6269281482a09ec15d1d49ca9f3ff395c Mon Sep 17 00:00:00 2001 From: koushik sreevatsa Date: Thu, 7 May 2026 15:06:44 -0400 Subject: [PATCH] fix: guard against falsy-value traps in psycopg2, chromadb, weaviate mocks Three test mocks mishandled falsy values, causing mock tests to pass while real-service tests would fail: psycopg2: bool is a subclass of int in Python, so isinstance(False, int) returns True. SQL WHERE params like isDeleted=False were incorrectly matched as LIMIT values. Fixed by adding not isinstance(p, bool) guards in _handle_semantic_search and _extract_limit. chromadb: 'if limit and ...' treated limit=0 as falsy, returning all rows instead of zero rows. Fixed with explicit 'limit is not None' check. weaviate: sort key 'distance if distance else 1.0' collapsed 0.0 (exact match, best possible distance) to 1.0, ranking perfect matches last. Fixed with 'distance if distance is not None else 1.0'. Resolves #748 --- nodes/test/mocks/chromadb/__init__.py | 2 +- nodes/test/mocks/psycopg2/__init__.py | 4 ++-- nodes/test/mocks/weaviate/__init__.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nodes/test/mocks/chromadb/__init__.py b/nodes/test/mocks/chromadb/__init__.py index e3260420f..a6255ee81 100644 --- a/nodes/test/mocks/chromadb/__init__.py +++ b/nodes/test/mocks/chromadb/__init__.py @@ -182,7 +182,7 @@ def get( count += 1 # Apply limit - if limit and len(results['ids']) >= limit: + if limit is not None and len(results['ids']) >= limit: break return results diff --git a/nodes/test/mocks/psycopg2/__init__.py b/nodes/test/mocks/psycopg2/__init__.py index 054d64667..2bc1d874e 100644 --- a/nodes/test/mocks/psycopg2/__init__.py +++ b/nodes/test/mocks/psycopg2/__init__.py @@ -182,7 +182,7 @@ def _handle_semantic_search(self, query: str, params: Tuple): query_vector = p.tolist() elif isinstance(p, (list, tuple)) and len(p) > 3: query_vector = list(p) - elif isinstance(p, int) and p < 1000: + elif isinstance(p, int) and not isinstance(p, bool) and p < 1000: limit = p else: filter_params.append(p) @@ -318,7 +318,7 @@ def _extract_limit(self, query: str, params: Tuple) -> Optional[int]: if 'limit' in query.lower() and params: # Last param is often the limit for p in reversed(params): - if isinstance(p, int) and p < 10000: + if isinstance(p, int) and not isinstance(p, bool) and p < 10000: return p return None diff --git a/nodes/test/mocks/weaviate/__init__.py b/nodes/test/mocks/weaviate/__init__.py index 6c6d44d4e..0662bbc92 100644 --- a/nodes/test/mocks/weaviate/__init__.py +++ b/nodes/test/mocks/weaviate/__init__.py @@ -278,7 +278,7 @@ def near_vector( ) # Sort by distance (lower is better for cosine distance) - results.sort(key=lambda x: x.metadata.distance if x.metadata.distance else 1.0) + results.sort(key=lambda x: x.metadata.distance if x.metadata.distance is not None else 1.0) return QueryResult(objects=results[:limit])