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

NotSupportedError contains a str, not a cx_Oracle._Error object #51

Closed
stuffybell opened this Issue Jul 20, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@stuffybell
Copy link

stuffybell commented Jul 20, 2017

When I follow the docs' guidance on exception handling, a NotSupportedError contains a string, not the expected cx_Oracle._Error object. Below is a short script that reproduces the issue. I'm using a dict as an example variable, but any unsupported variable type will throw this error.

from __future__ import print_function
import cx_Oracle

connection = cx_Oracle.Connection("cx_Oracle/dev@localhost/orcl")
cursor = connection.cursor()

my_dict = {"foo": 1, "bar": 2}

try:
    stmt = cursor.prepare("SELECT dummy FROM dual WHERE dummy = :myvar")
    cursor.execute(stmt, {"myvar": my_dict})

except cx_Oracle.DatabaseError as exc:
    print(str(type(exc)))                      # <class 'cx_Oracle.NotSupportedError'>
    print(repr(exc))                           # NotSupportedError('Variable_TypeByValue(): unhandled data type dict',)
    error, = exc.args                          # "error" is a str, NOT a cx_Oracle._Error object
    print("Oracle-Error-Code:", error.code)    # AttributeError: 'str' object has no attribute 'code'
    print("Oracle-Error-Message:", error.message)

The documentation states:

With cx_Oracle every exception object has exactly one argument in the args tuple. This argument is a cx_Oracle._Error object...

Environment

  • Python: 2.7.13 |Anaconda 4.3.1 (64-bit)
  • cx_Oracle: 5.2.1
  • Oracle client version: InstantClient 12.2 via rpm
  • Oracle database version: 12.2
  • OS: CentOS release 6.9 (Final)

@cjbj cjbj added the question label Jul 21, 2017

@anthony-tuininga

This comment has been minimized.

Copy link
Member

anthony-tuininga commented Jul 28, 2017

Thanks for pointing out the discrepancy between the documentation and the code. We'll address this. I'm leaning towards creating a cx_Oracle._Error object, even though some of the information in it will require default values. Is that what you would prefer, too?

@stuffybell

This comment has been minimized.

Copy link
Author

stuffybell commented Jul 31, 2017

Personally I would prefer that, just so all exceptions can be handled the same way. But I'm open to reasons why this is not desired. One I'm guessing you're alluding to is that the ".code" and ".message" properties would not correspond to an actual Oracle error message. Anyone else have any strong opinions?

anthony-tuininga added a commit that referenced this issue Mar 31, 2018

@anthony-tuininga

This comment has been minimized.

Copy link
Member

anthony-tuininga commented Mar 31, 2018

I have now implemented your suggestion. Thanks!

@stuffybell

This comment has been minimized.

Copy link
Author

stuffybell commented Apr 11, 2018

Thank you! Keep up the good work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment