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

Inconsistent Entity Property Values #37

Open

Description

@Andrei15193

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(),
        "BinaryProperty@odata.type": "Edm.Binary",
        "Boolean": "True",
        "Boolean@odata.type": "Edm.Boolean",
        "DateTime": "2018-12-10T20:33:53.4475462Z",
        "DateTime@odata.type": "Edm.DateTime",
        "Double": "1.2",
        "Double@odata.type": "Edm.Double",
        "Guid": "41ddfac7-8f88-4c6c-bc91-a0aa2f036b05",
        "Guid@odata.type": "Edm.Guid",
        "Int32": "3",
        "Int32@odata.type": "Edm.Int32",
        "Int64": "4",
        "Int64@odata.type": "Edm.Int64",
        "String": "4",
        "String@odata.type": "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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions