Skip to content

Azure Cosmos Module throws incorrect error type when not passing string for id item #11793

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

Closed
Rabbit994 opened this issue Jun 3, 2020 · 5 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization.
Milestone

Comments

@Rabbit994
Copy link

  • azure-cosmos:
  • 4.0.0:
  • Windows 10 Enterprise 1909:
  • Python 3.6.8:

Describe the bug
When attempting to upsert an item where 'id' field is not set to string, you get AttributeError.

While throwing error is correct in keeping with CosmosDB requirements that ID field be string, I believe TypeError in following with Python standards is more appropriate error.

https://docs.python.org/3/library/exceptions.html
Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError

To Reproduce
Steps to reproduce the behavior:
from azure.cosmos import exceptions, CosmosClient, PartitionKey
import random
#CHANGEME
endpoint = "changeme"
key = "changeme"

client = CosmosClient(endpoint, key)

database_name = 'AzureSampleFamilyDatabase'
database = client.create_database_if_not_exists(id=database_name)

container_name = 'FamilyContainer'
container = database.create_container_if_not_exists(
id=container_name,
partition_key=PartitionKey(path="/lastName"),
offer_throughput=400
)
item = {"id": (random.randint(1,100000))} #this should be string but isn't
item['lastname'] = "Jones"
container.upsert_item(item) #Attribute Error raised

AttributeError: 'int' object has no attribute 'find'

Expected behavior
Since id is not string, I would expect ValueError in keeping with Python standards

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 3, 2020
@kaerm kaerm added bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Cosmos and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 3, 2020
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jun 3, 2020
@kaerm
Copy link
Contributor

kaerm commented Jun 3, 2020

Thanks @Rabbit994 for posting the issue, @southpolesteve, @annatisch could you take a look at this

@Rabbit994
Copy link
Author

File "C:\Users\rabbit\Python Projects\AzureCosmosDBTesting.env\lib\site-packages\azure\cosmos_cosmos_client_connection.py", line 2483, in ValidateResource
if id
.find("/") != -1 or id
.find("\") != -1 or id_.find("?") != -1 or id_.find("#") != -1:
AttributeError: 'int' object has no attribute 'find'

There is exact error with line number to assist in debugging.

@annatisch
Copy link
Member

Thank you @Rabbit994 - good call - I will get a PR out for this this week :)

@annatisch
Copy link
Member

Thanks @Rabbit994 - this fix has been merged and will ship with the next release.
I'm not sure when that will be yet - I will close this issue once the release is out.

@lmazuel lmazuel added this to the [2020] July milestone Jun 9, 2020
@lmazuel lmazuel modified the milestones: [2020] July, [2020] August Jul 14, 2020
@annatisch
Copy link
Member

This fix has now been released.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization.
Projects
None yet
Development

No branches or pull requests

5 participants