question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve error handling for unsupported object types

See original GitHub issue

If 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:open
  • Created 8 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
LukeWoodwardcommented, Oct 4, 2017

@keshavnagpal: the only thing I can suggest is that you edit the pypyodbc.py file, find the line return type(v) within the get_type function and replace it with something like the following:

    raise TypeError("Value {0} of type {1} is not supported".format(v, type(v)))

That should improve the error handling and tell you the type of the value you are passing in that is causing the problem.

0reactions
keshavnagpalcommented, Jan 4, 2018

@LukeWoodward : Thanks a lot!

edit the pypyodbc.py file, find the line return type(v) within the get_type function and replace it with something like the following:

raise TypeError("Value {0} of type {1} is not supported".format(v, type(v))

This worked

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found