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.

Overwriting OData.Type #38

Open
Open

Description

@Andrei15193

One way to specify the EDM type of a property is by providing an additional propertyName + "@odata.type" value which tells the EDM type of the property. This works perfectly if the type is specified after said property, but if it is before then it gets overwritten.

For instance, the code bellow sets the EDM type accordingly. Even through I pass an integer the OData type of the property is set to string and a string is returned.

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

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

try:
    table_service.create_table(table_name)
    entity = {
        "PartitionKey": "partitionKey",
        "RowKey": "rowKey",
        "Int32": 3,
        "Int32@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)

On the other hand, if I specify the EDM type before it is ignored and an integer is stored.

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

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

try:
    table_service.create_table(table_name)
    entity = {
        "PartitionKey": "partitionKey",
        "RowKey": "rowKey",
        "Int32@odata.type": "Edm.String",
        "Int32": 3
    }
    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 have already created a PR fixing this: #34. For more information please see azure-cli/8032 Inserting Entity Sets Unexpected OData Type for Numeric Values.

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