Skip to content
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

Exception in read-document.ts getCollectionPartitionKeys when collection has no partitionKey saved #48

Closed
dsschneidermann opened this issue Oct 31, 2020 · 0 comments · Fixed by #49

Comments

@dsschneidermann
Copy link
Contributor

This is from working on compatibility with the CosmosDb CSharp SDK

Error logged request:

output for read-document.ts: getCollectionPartitionKeys(collection: ItemObject):
collection: {
  geospatialConfig: {},
  id: 'main',
  indexingPolicy: {
    automatic: true,
    indexingMode: 'consistent',
    includedPaths: [ [Object] ],
    excludedPaths: [],
    compositeIndexes: [],
    spatialIndexes: []
  },
  _etag: '96751c73-738f-46df-aa37-54aa6dc133b5',
  _rid: 'gAABAIAAAAM=',
  _self: '/dbs/gAABAA==/colls/gAABAIAAAAM=',
  _ts: 1604120454
}
TypeError: Cannot read property 'paths' of undefined
    at getCollectionPartitionKeys (/app/node_modules/@zeit/cosmosdb-server/lib/handler/read-document.js:15:36)
    at exports.default (/app/node_modules/@zeit/cosmosdb-server/lib/handler/read-document.js:61:32)
    at /app/node_modules/run-cosmosdb-sim/index.js:97:34
    at Server.<anonymous> (/app/node_modules/run-cosmosdb-sim/index.js:131:11)
    at Server.emit (events.js:314:20)
    at parserOnIncoming (_http_server.js:779:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:122:17)
{
   "method":"GET",
   "url":"/dbs/devicesimulation/colls/main/docs/MasterNode",
   "docdbHeaders":[
      "x-ms-documentdb-partitionkey",
      "[]"
   ],
   "response":{
      "statusCode":500,
      "statusMessage":"Internal Server Error",
      "headers":{
         "content-type":"application/json",
         "content-location":"https://cosmosdb-sim:3000/dbs/devicesimulation/colls/main/docs/MasterNode",
         "connection":"close",
         "x-ms-activity-id":"7ac85c27-a88b-4099-bb94-e405df69f721",
         "x-ms-request-charge":"1"
      },
      "body":{
         "message":"Cannot read property 'paths' of undefined"
      }
   },
   "errorMessage":null
}

Expected result:

  • Document is returned

Cause:

  • Somehow the SDK or cosmosdb-server did not save an empty partition key for this document, and fails when retrieving it.

Proposed fix by this PR:

  • Add a conditional check on collection.partitionKey and return an empty list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant