Open nicolaibaralmueller opened 4 years ago
Hello,
I have the same problem with MySQL database https://github.com/RamyChaabane/mysql_query
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: Value of unknown type: <type 'exceptions.TypeError'>, Value of unknown type: <class 'decimal.Decimal'>, 52166.10
Manually:
db_connect = pymysql.Connect(*connection_params) with db_connect.cursor() as cursor: ... cursor.execute("select from payments where customerNumber='496' and paymentDate='2004-12-31'") ... re = cursor.fetchall() ... 1 print re [{u'checkNumber': 'MN89921', u'amount': Decimal('52166.10'), u'customerNumber': 496, u'paymentDate': datetime.date(2004, 12, 31)}]
I found casting INT column results to CHAR type works: SELECT CAST( column1 AS CHAR) AS header, CAST(SUM(column2) AS CHAR) AS total FROM wherever...
I see this is pretty old but I ran into this issue and found a fix for it so I thought I'd post it up. Basically the error is from the ansible module trying to convert the sql output to json. I think this happens in the module.exit_json
method.
As a fix, instead of letting ansible try to convert the python object to json, I converted it to json myself. so something like:
query_result = cursor.fetchall()
result = json.dumps(query_result, default=str)
that should cover any non json-able data types like decimal, datetime, etc.
Using below query fails.
Executing the query manually produces no error. Seems that the module does not support decimal datatypes in the output.