Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Inconsistent Entity Property Values #37

Open
Andrei15193 opened this issue Feb 17, 2019 · 0 comments
Open

Inconsistent Entity Property Values #37

Andrei15193 opened this issue Feb 17, 2019 · 0 comments

Comments

@Andrei15193
Copy link

I've been using the Azure Table Storage CLI that is built on top of the Python SDK. One of the issues I noticed that in some cases that when I query an entity I get an EntityProperty as a property value and in other cases I do not. From what I can gather I get an EntityProperty in the cases where the value cannot be inferred (through isinstance checks).

This is a bit inconvenient as I cannot just write a switch and compare entity.property.type to the EDM types that are available with table storage, I have to check whether the property value is an EntityProperty, if it is then I have to check its EDM type, if it isn't an EntityProperty then I need to do checks on the actual value. This has side-effects in the Azure CLI tools as well, see azure-cli/8033 OData Type is Not Always Specified When Querying Entities for more details.

The code bellow creates a test table, inserts an entity will all possible property types and retrieves it. If the property value is an EntityProperty then the type is displayed from property_value.type otherwise it is displayed from type(property_value).

import base64
from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity, EntityProperty

table_name = "inconsistententityproperties"
table_service = TableService(connection_string="UseDevelopmentStorage=true;")

try:
    table_service.create_table(table_name)
    entity = {
        "PartitionKey": "partitionKey",
        "RowKey": "rowKey",
        "BinaryProperty": base64.b64encode(b"\x00\x01\x02").decode(),
        "[email protected]": "Edm.Binary",
        "Boolean": "True",
        "[email protected]": "Edm.Boolean",
        "DateTime": "2018-12-10T20:33:53.4475462Z",
        "[email protected]": "Edm.DateTime",
        "Double": "1.2",
        "[email protected]": "Edm.Double",
        "Guid": "41ddfac7-8f88-4c6c-bc91-a0aa2f036b05",
        "[email protected]": "Edm.Guid",
        "Int32": "3",
        "[email protected]": "Edm.Int32",
        "Int64": "4",
        "[email protected]": "Edm.Int64",
        "String": "4",
        "[email protected]": "Edm.String"
    }
    table_service.insert_entity(table_name, entity)

    saved_entity = table_service.get_entity(table_name, "partitionKey", "rowKey")
    for property_name in saved_entity:
        property_value = saved_entity[property_name]
        if (isinstance(property_value, EntityProperty)):
            print(property_name, "=", property_value.value)
            print(property_name + "@odata.type", "=", property_value.type)
        else:
            print(property_name, "=", property_value)
            print(property_name + "@type", "=", type(property_value))
finally:
    table_service.delete_table(table_name)

I would like that all property values to be consistent, i.e.: for all of them to be EntityProperty instances or at least have a flag to retrieve them as such.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant