Repository navigation
Conversation
Reviewer's GuideUpdates Azure certification-error traversal to treat an omitted optional details field as a leaf node, while continuing to reject invalid non-list details values, and adds regression coverage for the schema-compliant case. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cloudpub/ms_azure/utils.py" line_range="559-561" />
<code_context>
if code == "invalidState" and "certification" in message.lower():
return True
- if not isinstance(item.get('details'), list):
+ details = item.get('details')
+ if details is None:
+ return False
+ if not isinstance(details, list):
raise InvalidSchema(f"Invalid schema for 'details' inside error object: {item}")
</code_context>
<issue_to_address>
**issue (bug_risk):** An explicitly present `"details": null` value is treated as equivalent to an omitted field and returns `False` instead of raising `InvalidSchema`, even though the Azure schema defines `details` as an optional array rather than a nullable value. This silently accepts malformed error payloads and can cause certification failures hidden behind such a payload to be classified as retryable.
**Triggers:** When Azure returns an error object containing `"details": null`.
**Suggested fix:** Check `if "details" not in item` for the omitted-field case, then retain the non-list validation so an explicit `null` remains invalid unless the schema is confirmed to allow it.
```suggestion
if "details" not in item:
return False
details = item.get('details')
```
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: cloudpub/ms_azure/utils.py:561
| if code == "invalidState" and "certification" in message.lower(): | ||
| return True | ||
| if not isinstance(item.get('details'), list): | ||
| details = item.get('details') |
There was a problem hiding this comment.
It will be simpler to let attrs class to "parse" item It should be generated based on json schema. So mypy will be able to check which keys can be null and report that early.
There was a problem hiding this comment.
Let's me update this part.
There was a problem hiding this comment.
Added schema support.
Per the Azure error schema (https://schema.mp.microsoft.com/schema/error/2022-07-01) , "details" is optional. Treat its absence as no further nesting rather than raising InvalidSchema. Assisted-by: Claude Sonnet 4.6
589aaf9 to
dfbe678
Compare
dfbe678 to
2e46fcb
Compare
| if details is None: | ||
| return False | ||
| if not isinstance(details, list): | ||
| raise InvalidSchema(f"Invalid schema for 'details' inside error object: {item}") |
There was a problem hiding this comment.
While I know this is the previous code, since you are changing the error condition you should make this error message more explicit. That way if it occurs the user reading the log knows exactly what caused the failure.
| raise InvalidSchema(f"Invalid schema for 'details' inside error object: {item}") | |
| raise InvalidSchema(f"Invalid value for 'details', a list is required. Object: {item}") |
| """Ensure a ``details`` field is either unset or a list.""" | ||
| if value is not None and not isinstance(value, list): | ||
| raise InvalidSchema( | ||
| f"Invalid schema for \"details\" on {type(instance).__name__}: {value!r}" |
There was a problem hiding this comment.
You should make this error message more explicit. That way if it occurs the user reading the log knows exactly what caused the failure.
| f"Invalid schema for \"details\" on {type(instance).__name__}: {value!r}" | |
| f"Invalid \"details\" on {type(instance).__name__}, a list is required: {value!r}" |
| @classmethod | ||
| def _assert_json_dict(cls, json: Any) -> None: | ||
| if not isinstance(json, dict): | ||
| raise InvalidSchema(f"Invalid schema for error object: {json!r}") |
There was a problem hiding this comment.
You should make this error message more explicit. That way if it occurs the user reading the log knows exactly what caused the failure.
| raise InvalidSchema(f"Invalid schema for error object: {json!r}") | |
| raise InvalidSchema(f"Invalid type, expected a dict: {json!r}") |
| @classmethod | ||
| def _assert_json_dict(cls, json: Any) -> None: | ||
| if not isinstance(json, dict): | ||
| raise InvalidSchema(f"Invalid schema for error object: {json!r}") |
There was a problem hiding this comment.
You should make this error message more explicit. That way if it occurs the user reading the log knows exactly what caused the failure.
| raise InvalidSchema(f"Invalid schema for error object: {json!r}") | |
| raise InvalidSchema(f"Invalid type, expected a dict: {json!r}") |
| if not value: | ||
| return [] | ||
| if not isinstance(value, list): | ||
| raise InvalidSchema(f"Invalid schema for \"errors\": {value!r}") |
There was a problem hiding this comment.
You should make this error message more explicit. That way if it occurs the user reading the log knows exactly what caused the failure.
| raise InvalidSchema(f"Invalid schema for \"errors\": {value!r}") | |
| raise InvalidSchema(f"Invalid format for \"errors\", expected a list: {value!r}") |
@beerparty @lslebodn PTAL
Per the Azure error schema (https://schema.mp.microsoft.com/schema/error/2022-07-01) , "details" is optional.
Treat its absence as no further nesting rather than raising InvalidSchema.
Related Jira - SPSTRAT-820
Assisted-by: Claude Sonnet 4.6
Summary by Sourcery
Handle optional Azure error details while preserving validation of malformed error payloads.
New Features:
Bug Fixes:
Enhancements:
Tests: