Skip to content

Python truthiness / isinstance traps in three test mocks #747

@TrishaReddygari

Description

@TrishaReddygari

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.

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