更新/合并操作在Azure Cosmos DB(表API)中找不到实体

时间:2019-01-24 17:30:14

标签: python azure azure-cosmosdb azure-cosmosdb-tables

数据:

In [66]: list(a.table_service.query_entities('Watchlists',filter="RowKey eq '106619222' "))[-1]
Out[66]: 
{'PartitionKey': '2019-01-24',
 'RowKey': '106619222',
 'Timestamp': datetime.datetime(2019, 1, 24, 16, 36, 45, 474017, tzinfo=tzutc()),
 'avg_vol': 194.3305,
 'ftw_high': 14.68,
 'sell_price_high': 15.5608,
 'sell_price_low': 13.7992,
 'symbol': 'ACRE',
 'conId': 106619222,
 'date': datetime.datetime(2019, 1, 24, 0, 0, tzinfo=tzutc()),
 'is_breakout': False,
 'order_status': 'N/A',
 'last_price': nan,
 'last_volume': nan,
 'etag': 'W/"datetime\'2019-01-24T16%3A36%3A45.4740173Z\'"'}

In [67]: {k:(v.type,v.value) for k,v in entity.items()}
Out[67]: 
{'PartitionKey': ('Edm.String', '2019-01-24'),
 'RowKey': ('Edm.String', '106619222'),
 'Timestamp': ('Edm.DateTime',
  Timestamp('2019-01-24 16:36:45.474017+0000', tz='UTC')),
 'avg_vol': ('Edm.Double', 194.3305),
 'conId': ('Edm.Int64', 106619222),
 'date': ('Edm.DateTime', Timestamp('2019-01-24 00:00:00+0000', tz='UTC')),
 'ftw_high': ('Edm.Double', 14.68),
 'is_breakout': ('Edm.Boolean', False),
 'last_price': ('Edm.Double', 14.04),
 'last_volume': ('Edm.Double', 302.0),
 'order_status': ('Edm.String', 'N/A'),
 'sell_price_high': ('Edm.Double', 15.5608),
 'sell_price_low': ('Edm.Double', 13.7992),
 'symbol': ('Edm.String', 'ACRE')}

问题:

使用Table API拥有一个简单的Cosmos DB表,并且正在使用Python SDK。使用类azure.cosmosdb.table.tableservice.TableService和方法insert_or_replace_entity成功插入实体。

但是当我尝试更新它(使用merge_entityupdate_entity)时,它给了我这个错误(清理了格式,改写):

AzureMissingResourceHttpError: Not Found
{
    "odata.error": {
        "code": "ResourceNotFound",
        "message": {
            "lang": "en-us",
            "value": "The specified resource does not exist. RequestID: [REDACTED]"
        }
    }
}

当我尝试改为使用insert_or_merge_entity时,出现此错误:

AzureHttpError: Bad Request
{
    "odata.error": {
        "code": "BadRequest",
        "message": {
            "lang": "en-us",
            "value": "Requests originating from scripts cannot reference partition keys other than the one for which client request was submitted."
        }
    }
}

我假设Cosmos DB根据PartitionKey和RowKey的组合找到了匹配项,但是我包含了有效的PK和RK,但仍然失败。有人有解决方案吗?

谷歌搜索无济于事,仔细检查了文档https://docs.microsoft.com/en-us/rest/api/storageservices/update-entity2

1 个答案:

答案 0 :(得分:0)

找出答案。如果我将PartitionKey从EntityProperty更改为常规字符串,则可以使用。我在GitHub https://github.com/Azure/azure-cosmos-table-python/issues/35

上报道过,一定是个错误。