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

Overwriting OData.Type #38

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

Overwriting OData.Type #38

Andrei15193 opened this issue Feb 17, 2019 · 0 comments

Comments

@Andrei15193
Copy link

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,
        "[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)

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",
        "[email protected]": "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.

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