Skip to content

[Security] Unbound variable NameError on InfluxDB query failure #2

@dom-omg

Description

@dom-omg

File: common/src/common/database/influxdb.py line 491

Code:
try:
query_results = api_queryfcast.query_data_frame(query)
except Exception as e:
logger.info("An error occurred while querying data: %s", e)

  if query_results.empty:  # ← NameError if exception was raised above                                   

Problem:
query_results is assigned inside the try block only. If the InfluxDB query
raises an exception, query_results is never defined. Execution continues to
query_results.empty and raises NameError — silently crashing the data API.

Fix:
Initialize before the try block:
query_results = None
try:
query_results = api_queryfcast.query_data_frame(query)
except Exception as e:
logger.info(...)
return {"error": "The InfluxDB query failed to execute."}

  if query_results is None or query_results.empty:                                                       

Same pattern as predictive-control issue #3 (grap_info unbound).
Found via AST analysis — COBALT formal verification engine.

Reported by: Dominik Blain — COBALT verification

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