fix(RHIDP_15096): handle missing 'parameters' key in elasticsearch_loader.py - #178
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe Elasticsearch loader now safely extracts optional ChangesElasticsearch loader
Estimated code review effort: 1 (Trivial) | ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
90fa244 to
5eaccee
Compare
|
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
5eaccee to
d9009f7
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
core/opl/investigator/elasticsearch_loader.py
| 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')}" |
There was a problem hiding this comment.
🩺 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.
| 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.
…ader
Signed-off-by: skestwal skestwal@redhat.com
rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED