Azure Cosmos Module throws incorrect error type when not passing string for id item #11793
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
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
The text was updated successfully, but these errors were encountered: