Skip to content

Valid falsy lastScanTime (0) is silently dropped from REST index info BUG #191

Description

@celticht32

Summary

process_index_data_from_rest_api in src/cb_mcp/utils/index_utils.py validates that
lastScanTime is present (_validate_rest_row requires the key), then includes it
only when truthy:

if idx["lastScanTime"]:
    index_info["lastScanTime"] = idx["lastScanTime"]

A value of 0 (a legitimate timestamp/epoch meaning "never scanned" or "scanned at
epoch 0") is falsy, so the field is silently omitted from the output even though it
was present and valid. The validator required the key, so its absence in the result is
inconsistent with the contract the validator implies.

How to reproduce

from cb_mcp.utils.index_utils import process_index_data_from_rest_api as p
row = {"indexName": "i", "definition": "CREATE INDEX ...",
       "status": "Ready", "bucket": "b", "lastScanTime": 0}
out = p(row)
print("lastScanTime" in out)   # -> False   (dropped, though 0 is a valid value)

Verified against the current tree.

Impact

Minor but real: consumers relying on lastScanTime being present (because the
validator required it) will find it missing specifically when the value is 0. This
can misrepresent an index that has never been scanned versus one whose scan-time field
was absent.

Suggested fix

Distinguish "present" from "truthy":

if idx.get("lastScanTime") is not None:
    index_info["lastScanTime"] = idx["lastScanTime"]

or, since the validator already guarantees the key exists, include it unconditionally:

index_info["lastScanTime"] = idx["lastScanTime"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions