Skip to content

fix(ms-azure): handle missing "details" field in inner-error objects - #233

Open
ashwgit wants to merge 2 commits into
release-engineering:mainfrom
ashwinifork:swith-error-details-optional
Open

ashwgit wants to merge 2 commits into
release-engineering:mainfrom
ashwinifork:swith-error-details-optional

Conversation

@ashwgit

@ashwgit ashwgit commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

@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:

  • Model Azure configuration errors and nested inner errors as validated structured objects.

Bug Fixes:

  • Handle Azure inner-error objects that omit the optional details field without raising a schema error.

Enhancements:

  • Update certification-error detection to traverse typed Azure error objects and optional nested details.

Tests:

  • Add coverage for valid missing details fields and invalid Azure error payload shapes.

@sourcery-ai

sourcery-ai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Updates 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

Change Details Files
Handle optional inner-error details according to the Azure schema while preserving validation for malformed values.
  • Return no match when an error object omits details.
  • Continue raising InvalidSchema when details is present but not a list.
  • Iterate over the normalized details value during recursive certification-error detection.
cloudpub/ms_azure/utils.py
Add regression coverage for nested errors whose details field is absent.
  • Verify missing details does not raise InvalidSchema and is treated as non-certification-related.
  • Retain existing assertions for certification errors, valid non-certification errors, and empty input.
tests/ms_azure/test_utils.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread cloudpub/ms_azure/utils.py Resolved
Comment thread cloudpub/ms_azure/utils.py Outdated
if code == "invalidState" and "certification" in message.lower():
return True
if not isinstance(item.get('details'), list):
details = item.get('details')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Let's me update this part.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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
@ashwgit
ashwgit force-pushed the swith-error-details-optional branch from 589aaf9 to dfbe678 Compare November 5, 2026 05:40
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Nov 5, 2026

@sourcery-ai sourcery-ai 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.

Sourcery assessment

Approved.

@sourcery-ai sourcery-ai 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.

Sourcery assessment

Approved.

Comment thread cloudpub/ms_azure/utils.py Outdated
if details is None:
return False
if not isinstance(details, list):
raise InvalidSchema(f"Invalid schema for 'details' inside error object: {item}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Suggested change
raise InvalidSchema(f"Invalid schema for 'details' inside error object: {item}")
raise InvalidSchema(f"Invalid value for 'details', a list is required. Object: {item}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Refactor resolved this.

"""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}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should make this error message more explicit. That way if it occurs the user reading the log knows exactly what caused the failure.

Suggested change
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}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should make this error message more explicit. That way if it occurs the user reading the log knows exactly what caused the failure.

Suggested change
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}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should make this error message more explicit. That way if it occurs the user reading the log knows exactly what caused the failure.

Suggested change
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}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should make this error message more explicit. That way if it occurs the user reading the log knows exactly what caused the failure.

Suggested change
raise InvalidSchema(f"Invalid schema for \"errors\": {value!r}")
raise InvalidSchema(f"Invalid format for \"errors\", expected a list: {value!r}")

This branch has not been deployed

No deployments
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.

3 participants