Skip to content

fix(RHIDP_15096): handle missing 'parameters' key in elasticsearch_loader.py - #178

Merged
jhutar merged 2 commits into
redhat-performance:mainfrom
shashankkestwal:fix/RHIDP-15096
Jul 16, 2026
Merged

jhutar merged 2 commits into
redhat-performance:mainfrom
shashankkestwal:fix/RHIDP-15096

Conversation

@shashankkestwal

Copy link
Copy Markdown
Contributor

…ader

  item['_source']['parameters'] raises KeyError when documents
  don't include a 'parameters' field. Guard with .get()

Signed-off-by: skestwal skestwal@redhat.com

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved resilience when loading Elasticsearch results with missing document fields.
    • Enhanced diagnostic logging to avoid errors when identifiers or run parameters are unavailable.

Walkthrough

The Elasticsearch loader now safely extracts optional parameters data and uses .get(...) lookups for document IDs and parameters.run in debug logging.

Changes

Elasticsearch loader

Layer / File(s) Summary
Safe parameter and debug-field access
core/opl/investigator/elasticsearch_loader.py
load defaults missing parameters to an empty dictionary and safely accesses id and parameters.run when constructing debug logs.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the change to safely handle a missing parameters field in elasticsearch_loader.py.
Description check ✅ Passed The description is directly related, describing the KeyError from missing parameters and the fix using .get().
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@shashankkestwal shashankkestwal changed the title fix(RHIDP_15097): handle missing 'parameters' key in elasticsearch_lo… fix(RHIDP_15096): handle missing 'parameters' key in elasticsearch_loader.py Jul 8, 2026
@jhutar

jhutar commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Hello @shashankkestwal . Please fix linter issues (reformat with black) and I think we can push.

…ader

      item['_source']['parameters'] raises KeyError when documents
      don't include a 'parameters' field. Guard with .get()

Signed-off-by: skestwal <skestwal@redhat.com>

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/opl/investigator/elasticsearch_loader.py`:
- Around line 43-45: Update the parameters handling in the document-loading flow
to normalize or validate item["_source"].get("parameters", {}) before calling
params.get("run"). Ensure null and other non-mapping values are safely treated
as an empty mapping so the logging statement cannot raise AttributeError, while
preserving valid parameter mappings.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: fbf0309c-96d3-47e8-a863-1cf02e9e76f0

📥 Commits

Reviewing files that changed from the base of the PR and between d75925e and d9009f7.

📒 Files selected for processing (1)
  • core/opl/investigator/elasticsearch_loader.py

Comment on lines +43 to +45
params = item["_source"].get("parameters", {})
logging.debug(
f"Loading data from document ID {item['_id']} with field id={item['_source']['id'] if 'id' in item['_source'] else None} or parameters.run={item['_source']['parameters']['run'] if 'run' in item['_source']['parameters'] else None}"
f"Loading data from document ID {item['_id']} with field id={item['_source'].get('id')} or parameters.run={params.get('run')}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Handle non-object parameters values as well.

.get("parameters", {}) only defaults when the key is missing. A document with parameters: null (or another non-mapping value) still makes params.get("run") raise AttributeError and abort the whole load. Normalize or validate the value before logging.

Proposed fix
-        params = item["_source"].get("parameters", {})
+        params = item["_source"].get("parameters")
+        if not isinstance(params, dict):
+            params = {}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
params = item["_source"].get("parameters", {})
logging.debug(
f"Loading data from document ID {item['_id']} with field id={item['_source']['id'] if 'id' in item['_source'] else None} or parameters.run={item['_source']['parameters']['run'] if 'run' in item['_source']['parameters'] else None}"
f"Loading data from document ID {item['_id']} with field id={item['_source'].get('id')} or parameters.run={params.get('run')}"
params = item["_source"].get("parameters")
if not isinstance(params, dict):
params = {}
logging.debug(
f"Loading data from document ID {item['_id']} with field id={item['_source'].get('id')} or parameters.run={params.get('run')}"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/opl/investigator/elasticsearch_loader.py` around lines 43 - 45, Update
the parameters handling in the document-loading flow to normalize or validate
item["_source"].get("parameters", {}) before calling params.get("run"). Ensure
null and other non-mapping values are safely treated as an empty mapping so the
logging statement cannot raise AttributeError, while preserving valid parameter
mappings.

@jhutar
jhutar merged commit 17c7735 into redhat-performance:main Jul 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants