CosmosDB cannot read out documents with URL encoded IDs
We had a Cosmos DB account and in one of the containers some of the documents have URL encoded IDs, e.g.: rfq_123_%28test%29 meaning "rfq_123_(test)". I'm no fan of url encoded IDs, but I'm just supporting the project and it's too late to change.
We could read this document via Data Explorer in the Azure Portal by clicking on the document.
The account was destroyed and restored (point in time) to a temporary account as part of our disaster recovery plan. The restored account also works as expected.
We then provisioned a new Cosmos DB account via Terraform and used a az cli based copy script to copy data from the temporary account to the new account.
After the data was copied, however we could no longer read out documents with url encoded IDs, so when clicking on said document in the new account, we got the following error:
Failed to read item rfq_123_%28test%29: The input authorization token can't serve the request. The wrong key is being used or the expected payload is not built as per the protocol. For more info: https://aka.ms/cosmosdb-tsg-unauthorized. Server used the following payload to sign: 'get docs dbs/master/colls/test/docs/rfq_123_(test) thu, 25 jul 2024 11:45:44 gmt
We can still query the document and get the document content:
SELECT * FROM c WHERE c.id = 'rfq_123_%28test%29'
I have diff'ed all settings and configurations between the restored (working) account and the new account with copied data. They are identical apart from the restored account having some irrelevant restore timestamp related settings.
Now to the real joker: After about 22-24 hours, the new account suddenly started to work again. Documents with url encoded IDs could be read from the Data Explorer in the Portal.
I felt a bit uncomfortable about that, so I tried manually creating a new Cosmos DB account, added a container with the same settings as my real account and manually inserted a document with a url encoded ID. Lo and behold: The document is inserted, but cannot be read via the Portal or the SDK.
This definitely seems like a critical Cosmos DB bug and any support would be appreciated.
To reproduce:
- Create a new Cosmos DB account.
- Add a database and container.
- Insert dummy document with a url encoded ID, e.g. rfq_123_%28test%29
- Try to read the document from the Data Explorer.
- This will result in an error message in the portal.