BUG-HUNT: [error-handling] Potential AttributeError in robot.json_helper.get_dict_keys #2822

Open
opened 2026-04-04 20:40:44 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/error-handling-json-helper-get-dict-keys
  • Commit Message: fix(error-handling): add isinstance check in robot.json_helper.get_dict_keys to prevent AttributeError
  • Milestone: v3.7.0
  • Parent Epic: #362

Description

The get_dict_keys method in robot/json_helper.py does not validate that the value at data[key] is a dictionary before calling .keys() on it. If a test case passes a dictionary where the value at the specified key is not a dictionary (e.g., a string, integer, or list), this will raise an AttributeError, causing the test case to crash unexpectedly.

Location

  • File: robot/json_helper.py
  • Function/Class: JsonHelper.get_dict_keys
  • Lines: 21–25

Evidence

@staticmethod
def get_dict_keys(data, key):
    """Get keys from a nested dictionary."""
    if key in data:
        return list(data[key].keys())
    return []

Expected Behavior

The method should check if data[key] is a dictionary before attempting to access its keys. If it is not a dictionary, it should return an empty list.

Actual Behavior

The method raises an AttributeError if data[key] is not a dictionary (e.g., a string, integer, or list).

Suggested Fix

@staticmethod
def get_dict_keys(data, key):
    """Get keys from a nested dictionary."""
    if key in data and isinstance(data[key], dict):
        return list(data[key].keys())
    return []

Severity Assessment

  • Impact: Low — a test case could crash if it passes a dictionary where the value of the specified key is not a dictionary.
  • Likelihood: Low — test cases are likely to pass dictionaries with the expected structure.
  • Priority: Low

Subtasks

  • Add isinstance(data[key], dict) guard to JsonHelper.get_dict_keys in robot/json_helper.py
  • Add type annotations to the method signature
  • Write a Behave unit test scenario covering the case where data[key] is not a dictionary (e.g., a string, integer, list)
  • Write a Behave unit test scenario covering the happy path (key present and value is a dict)
  • Write a Behave unit test scenario covering the case where the key is absent
  • Ensure all nox quality gates pass (nox -e lint, nox -e typecheck, nox -e unit_tests, nox -e coverage_report)

Definition of Done

  • JsonHelper.get_dict_keys returns an empty list when data[key] is not a dictionary, instead of raising AttributeError
  • All new and existing Behave unit tests pass (nox -e unit_tests)
  • Static type annotations are present and pass Pyright (nox -e typecheck)
  • Linting passes (nox -e lint)
  • All nox stages pass
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/error-handling-json-helper-get-dict-keys` - **Commit Message**: `fix(error-handling): add isinstance check in robot.json_helper.get_dict_keys to prevent AttributeError` - **Milestone**: v3.7.0 - **Parent Epic**: #362 ## Description The `get_dict_keys` method in `robot/json_helper.py` does not validate that the value at `data[key]` is a dictionary before calling `.keys()` on it. If a test case passes a dictionary where the value at the specified key is not a dictionary (e.g., a string, integer, or list), this will raise an `AttributeError`, causing the test case to crash unexpectedly. ### Location - **File**: `robot/json_helper.py` - **Function/Class**: `JsonHelper.get_dict_keys` - **Lines**: 21–25 ### Evidence ```python @staticmethod def get_dict_keys(data, key): """Get keys from a nested dictionary.""" if key in data: return list(data[key].keys()) return [] ``` ### Expected Behavior The method should check if `data[key]` is a dictionary before attempting to access its keys. If it is not a dictionary, it should return an empty list. ### Actual Behavior The method raises an `AttributeError` if `data[key]` is not a dictionary (e.g., a string, integer, or list). ### Suggested Fix ```python @staticmethod def get_dict_keys(data, key): """Get keys from a nested dictionary.""" if key in data and isinstance(data[key], dict): return list(data[key].keys()) return [] ``` ### Severity Assessment - **Impact**: Low — a test case could crash if it passes a dictionary where the value of the specified key is not a dictionary. - **Likelihood**: Low — test cases are likely to pass dictionaries with the expected structure. - **Priority**: Low ## Subtasks - [ ] Add `isinstance(data[key], dict)` guard to `JsonHelper.get_dict_keys` in `robot/json_helper.py` - [ ] Add type annotations to the method signature - [ ] Write a Behave unit test scenario covering the case where `data[key]` is not a dictionary (e.g., a string, integer, list) - [ ] Write a Behave unit test scenario covering the happy path (key present and value is a dict) - [ ] Write a Behave unit test scenario covering the case where the key is absent - [ ] Ensure all nox quality gates pass (`nox -e lint`, `nox -e typecheck`, `nox -e unit_tests`, `nox -e coverage_report`) ## Definition of Done - [ ] `JsonHelper.get_dict_keys` returns an empty list when `data[key]` is not a dictionary, instead of raising `AttributeError` - [ ] All new and existing Behave unit tests pass (`nox -e unit_tests`) - [ ] Static type annotations are present and pass Pyright (`nox -e typecheck`) - [ ] Linting passes (`nox -e lint`) - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
freemo added this to the v3.7.0 milestone 2026-04-04 20:40:53 +00:00
freemo removed this from the v3.7.0 milestone 2026-04-07 00:42:07 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#362 Epic: Security & Safety Hardening
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#2822
No description provided.