Three subtle Python truthiness / isinstance bugs in the test mocks under nodes/test/mocks/. Identified by CodeRabbit during review of #744. All three are the same class of bug — relying on Python truthiness when is not None / a bool guard is what's actually needed.
1. psycopg2 mock — booleans match isinstance(p, int)
nodes/test/mocks/psycopg2/__init__.py (line 185 in _handle_semantic_search, and line 307 in _extract_limit) uses isinstance(p, int) and p < 1000 to detect a LIMIT parameter. Because bool is a subclass of int in Python (isinstance(False, int) is True), boolean params — e.g. False from isDeleted = %s — get assigned to limit instead of appended to filter_params. This silently breaks WHERE filtering whenever a query has both an int LIMIT and bool parameters.
2. chromadb mock — limit=0 treated as "no limit"
nodes/test/mocks/chromadb/__init__.py line 169 uses if limit and len(results['ids']) >= limit:. Because 0 is falsy in Python, calling get(limit=0) returns all rows instead of zero.
3. weaviate mock — sort collapses 0.0 distance
nodes/test/mocks/weaviate/__init__.py line 268 sorts with key=lambda x: x.metadata.distance if x.metadata.distance else 1.0. Because 0.0 is falsy, exact-match results (cosine distance 0.0) get the fallback value 1.0 and rank last in nearest-neighbor order instead of first.
Why these matter
These are test mocks, so production runtime isn't directly affected. But mock-only bugs of this kind are dangerous: tests pass against the mock, then real behavior diverges in production, and the gap is hard to spot.
Proposed approach
All three fixes are one-liners. PR coming as a single change with three commits, one per file, so each fix is independently reviewable.
Three subtle Python truthiness /
isinstancebugs in the test mocks undernodes/test/mocks/. Identified by CodeRabbit during review of #744. All three are the same class of bug — relying on Python truthiness whenis not None/ a bool guard is what's actually needed.1.
psycopg2mock — booleans matchisinstance(p, int)nodes/test/mocks/psycopg2/__init__.py(line 185 in_handle_semantic_search, and line 307 in_extract_limit) usesisinstance(p, int) and p < 1000to detect a LIMIT parameter. Becauseboolis a subclass ofintin Python (isinstance(False, int) is True), boolean params — e.g.FalsefromisDeleted = %s— get assigned tolimitinstead of appended tofilter_params. This silently breaks WHERE filtering whenever a query has both anintLIMIT andboolparameters.2.
chromadbmock —limit=0treated as "no limit"nodes/test/mocks/chromadb/__init__.pyline 169 usesif limit and len(results['ids']) >= limit:. Because0is falsy in Python, callingget(limit=0)returns all rows instead of zero.3.
weaviatemock — sort collapses0.0distancenodes/test/mocks/weaviate/__init__.pyline 268 sorts withkey=lambda x: x.metadata.distance if x.metadata.distance else 1.0. Because0.0is falsy, exact-match results (cosine distance0.0) get the fallback value1.0and rank last in nearest-neighbor order instead of first.Why these matter
These are test mocks, so production runtime isn't directly affected. But mock-only bugs of this kind are dangerous: tests pass against the mock, then real behavior diverges in production, and the gap is hard to spot.
Proposed approach
All three fixes are one-liners. PR coming as a single change with three commits, one per file, so each fix is independently reviewable.