Improve error handling for unsupported object types
See original GitHub issueIf you pass pypyodbc a value of some type it doesn’t know how to convert, the end result is an error message which doesn’t give you much information about what you’ve done wrong.
Take for example the following code:
import pypyodbc as pyodbc
class SomeClass(object): pass
obj = SomeClass()
cnxn = pyodbc.connect('....')
cursor = cnxn.cursor()
cursor.execute("INSERT INTO some_table (a) VALUES (?)", [obj])
When I run this code, it generates the following traceback:
Traceback (most recent call last):
File "C:\Users\Luke\StackOverflow\pypyodbctest.py", line 9, in <module>
cursor.execute("INSERT INTO some_table (a) VALUES (?)", [obj])
File "C:\Python27\lib\site-packages\pypyodbc.py", line 1470, in execute
self._BindParams(param_types)
File "C:\Python27\lib\site-packages\pypyodbc.py", line 1275, in _BindParams
if param_types[col_num][0] == 'u':
TypeError: 'type' object has no attribute '__getitem__'
From this message alone it can be difficult to figure out what has been done wrong.
In my sample code I can fully expect that there will be a problem, as I haven’t specified anything about how a SomeClass
instance should be converted into a SQL datatype. However, the same error message appears in this StackOverflow question where it was less clear to the questioner what their mistake was.
Issue Analytics
- State:
- Created 8 years ago
- Comments:8
Top Results From Across the Web
Is there any method that solve unsupported object type float ...
It showed me 'Failed to convert a NumPy array to a Tensor (Unsupported object type float)'. I want to know how and where...
Read more >How to Fix the Unsupported Operation Exception in Java
The UnsupportedOperationException can be resolved by using a mutable collection, such as ArrayList , which can be modified. An unmodifiable ...
Read more >[Security Solution]Unsupported object type error on importing ...
Describe the bug Unsupported object type error on importing exported case on 7.15.2 from 7.16.0 Build Details Version:7.16.0 ...
Read more >"Unsupported object type in Metric" error occurs when running ...
When running multi-source report which included customized MDX Cube compound metric, the following error message appears. This problem only ...
Read more >Handling TypeError Exception in Python - GeeksforGeeks
... incorrect/unsupported object type. For example, using the + (addition) operator on a string and an integer value will raise TypeError.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@keshavnagpal: the only thing I can suggest is that you edit the pypyodbc.py file, find the line
return type(v)
within theget_type
function and replace it with something like the following:That should improve the error handling and tell you the type of the value you are passing in that is causing the problem.
@LukeWoodward : Thanks a lot!
This worked