Azure/azure-cosmos-python

Error Not Found: Entity with the specified id does not exist in the system

Closed this issue · 3 comments

When trying to read a document, I get this error:

HTTPFailure: Status code: 404
{"code":"NotFound","message":"Entity with the specified id does not exist in the system., \r\nRequestStartTime: 2019-03-28T15:49:32.0893319Z, RequestEndTime: 2019-03-28T15:49:32.0993162Z, Number of regions attempted: 1\r\nResponseTime: 2019-03-28T15:49:32.0993162Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-westeurope1-fd21.documents.azure.com:16795/apps/6657d7ac-94f1-4464-8bdd-5c881515c4a2/services/d0ac5c93-a0d7-4930-908b-3c2a2a097a19/partitions/bfe8a00f-3362-4c5d-a786-b7dfb44cf2c3/replicas/131979921110575891s/, LSN: 65, GlobalCommittedLsn: 64, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#65, UsingLocalLSN: True, TransportException: null, ResourceType: Document, OperationType: Read\r\n, Microsoft.Azure.Documents.Common/2.2.0.0"}

Here's the code:

def ReadDocuments():
        documentlist = list(client.ReadItems(collection_link))
        
        print('Found {0} documents'.format(documentlist.__len__()))
        
        for doc in documentlist:
            docId = doc.get('id')
            print('Document Id: {0}'.format(docId))
            #ReadDocument(docId)
            
            
def ReadDocument(doc_id):
        doc_link = collection_link + '/docs/' + doc_id
        response = client.ReadItem(doc_link,{'partitionKey':'/name'})

        print('Document read by Id {0}'.format(doc_id))

Do you have any idea what might be causing this issue?

Thanks

Is it failing in ReadDocuments or ReadDocument?

Where is collection_link getting configured?

Usually I see this from ReadDocuments when you have a typo in your collection_link and it thinks that the database or collection doesn't exist.

It is failing in ReadDocument.
There is no problem with ReadDocuments, I can display the IDs of all the documents in the collection. I pass the ID to ReadDocument down from there so I know that they exist, but when trying to read them I get a 404 error.

The partition key you're passing in request options needs to be the value, not the path.

So if your document is like:

{
    "id":"foo",
    "name":"baz"
}

Your code would call

doc_link = collection_link + '/docs/' + doc_id
response = client.ReadItem(doc_link,{'partitionKey':'baz'})

You should modify your ReadDocument call to take in both properties:

def ReadDocument(doc_id, pk):
        doc_link = collection_link + '/docs/' + doc_id
        response = client.ReadItem(doc_link,{'partitionKey':'pk})

        print('Document read by Id {0}'.format(doc_id))

ReadDocument('foo', 'baz')

Also FYI, id is only unique within a partition key. So each pair (id, pk) is unique, but neither by itself is unique.