-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Conversation
…into tvaron3/noneCollectionId
…into tvaron3/noneCollectionId
/azp run python - cosmos - ci |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run python - cosmos - ci |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run python - cosmos - ci |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this 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 returnstr
and raise aValueError
on parse failure - Remove redundant
str()
casts when passingcollection_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
toGetResourceIdOrFullNameFromLink
raises aValueError
as expected.
raise ValueError("Failed Parsing ResourceID from link: {0}".format(resource_link))
/azp run python - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.