Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError("Cannot convert %r to Decimal" % value) #157

Closed
spacentropy opened this issue Aug 20, 2019 · 2 comments
Closed

TypeError("Cannot convert %r to Decimal" % value) #157

spacentropy opened this issue Aug 20, 2019 · 2 comments

Comments

@spacentropy
Copy link

Repro

from azure.kusto.data.request import KustoClient, KustoConnectionStringBuilder
from azure.kusto.data.exceptions import KustoServiceError

kcsb = KustoConnectionStringBuilder.with_aad_application_key_authentication(
    connection_string='',
    aad_app_id='',
    app_key='',
    authority_id='')

client = KustoClient(kcsb)

db = 'db'
try:
    query = "T"
    response = client.execute(db, query)

except KustoServiceError as error:
    response = None

print response.primary_results[0]

schema:

.create table T (a:string, b:decimal)
.ingest inline into table T
[,]

Problem description

Code fails with error TypeError: Cannot convert None to Decimal
It's because of:

  1. Decimal is value type and is not nullable in Python
  2. It is a nullable type in Kusto
  3. Kusto sends us null
  4. we are trying to convert null to Decimal:
    typed_value = KustoResultRow.convertion_funcs[column_type](value)
  5. adding decimal to this if fixes problem
    if column_type in ["datetime", "timespan"]:

full stacktrace:

File "test.py", line 17, in <module>
    response = client.execute(db, query)
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/azure/kusto/data/request.py", line 396, in execute
    return self.execute_query(database, query, properties)
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/azure/kusto/data/request.py", line 407, in execute_query
    self._query_endpoint, database, query, None, KustoClient._query_default_timeout, properties
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/azure/kusto/data/request.py", line 462, in _execute
    return KustoResponseDataSetV2(response.json())
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/azure/kusto/data/_response.py", line 134, in __init__
    super(KustoResponseDataSetV2, self).__init__([t for t in json_response if t["FrameType"] == "DataTable"])
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/azure/kusto/data/_response.py", line 18, in __init__
    self.tables = [KustoResultTable(t) for t in json_response]
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/azure/kusto/data/_models.py", line 137, in __init__
    self.rows = [KustoResultRow(self.columns, row) for row in json_table["Rows"]]
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/azure/kusto/data/_models.py", line 71, in __init__
    typed_value = KustoResultRow.convertion_funcs[column_type](value)
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py", line 657, in __new__
    raise TypeError("Cannot convert %r to Decimal" % value)
TypeError: Cannot convert None to Decimal

Output of pip freeze

adal==1.2.2
asn1crypto==0.24.0
azure-kusto-data==0.0.31
azure-nspkg==3.0.2
certifi==2019.6.16
cffi==1.12.3
chardet==3.0.4
cryptography==2.7
enum34==1.1.6
idna==2.8
ipaddress==1.0.22
pbr==5.4.2
pycparser==2.19
PyJWT==1.7.1
python-dateutil==2.8.0
requests==2.22.0
six==1.12.0
stevedore==1.30.1
urllib3==1.25.3
virtualenv==16.7.2
virtualenv-clone==0.5.3
virtualenvwrapper==4.8.4
@spacentropy
Copy link
Author

Fixed in e626d40

@spacentropy
Copy link
Author

Will close after 0.0.32 lands

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

No branches or pull requests

2 participants