8000 Explicitily fail instead of returning null if cannot parse resource link by tvaron3 · Pull Request #41353 · Azure/azure-sdk-for-python · GitHub
[go: up one dir, main page]

Skip to content

Explicitily fail instead of returning null if cannot parse resource link #41353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 9, 2025

Conversation

tvaron3
Copy link
Member
@tvaron3 tvaron3 commented May 29, 2025

Description

Don't return None when parsing the collection id rather raise an error. If we return, none in the future it would break lots of parts of the sdk with a key error.

@simorenoh
Copy link
Member

/azp run python - cosmos - ci

Copy link
Azure Pipelines successfully started running 1 pipeline(s).

@tvaron3
Copy link
Member Author
tvaron3 commented Jun 3, 2025

/azp run python - cosmos - ci

Copy link
Azure Pipelines successfully started running 1 pipeline(s).

@tvaron3
Copy link
Member Author
tvaron3 commented Jun 4, 2025

/azp run python - cosmos - ci

Copy link
Azure Pipelines successfully started running 1 pipeline(s).

@tvaron3 tvaron3 marked this pull request as ready for review June 4, 2025 04:00
@Copilot Copilot AI review requested due to automatic review settings June 4, 2025 04:00
@tvaron3 tvaron3 requested a review from a team as a code owner June 4, 2025 04:00
Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the resource link parsing logic to fail fast by raising an exception instead of returning None, and propagates the raw string ID through routing map initialization.

  • Change GetResourceIdOrFullNameFromLink to return str and raise a ValueError on parse failure
  • Remove redundant str() casts when passing collection_id into routing map providers
  • Ensure both sync and async routing map providers use the updated signature

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
sdk/cosmos/azure-cosmos/azure/cosmos/_routing/routing_map_provider.py Removed str() cast when calling init_collection_routing_map_if_needed
sdk/cosmos/azure-cosmos/azure/cosmos/_routing/aio/routing_map_provider.py Same removal of str() cast in async provider
sdk/cosmos/azure-cosmos/azure/cosmos/_base.py Updated GetResourceIdOrFullNameFromLink signature to -> str and replaced return None with a ValueError
Comments suppressed due to low confidence (3)

sdk/cosmos/azure-cosmos/azure/cosmos/_base.py:349

  • Update the docstring to include a :raises ValueError: section, clarifying that the function now throws an exception when parsing fails.
def GetResourceIdOrFullNameFromLink(resource_link: str) -> str:

sdk/cosmos/azure-cosmos/azure/cosmos/_base.py:382

  • [nitpick] Consider revising the error message to follow consistent capitalization and provide more context, e.g. Failed parsing resource ID from link: {resource_link}.
raise ValueError("Failed Parsing ResourceID from link: {0}".format(resource_link))

sdk/cosmos/azure-cosmos/azure/cosmos/_base.py:382

  • Add a unit test to verify that passing an invalid resource_link to GetResourceIdOrFullNameFromLink raises a ValueError as expected.
raise ValueError("Failed Parsing ResourceID from link: {0}".format(resource_link))

@tvaron3
Copy link
Member Author
tvaron3 commented Jun 5, 2025

/azp run python - cosmos - tests

Copy link
Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor
@allenkim0129 allenkim0129 left a comment

Choose a reason for hiding this comment

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

LGTM

@tvaron3 tvaron3 merged commit 17c5712 into Azure:main Jun 9, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants
0