oracle / python-oracledb

Python driver for Oracle Database conforming to the Python DB API 2.0 specification. This is the renamed, new major release of cx_Oracle
https://oracle.github.io/python-oracledb
Other
339 stars 67 forks source link

AttributeError: 'NoneType' object has no attribute 'SSLError' #59

Closed tobyych closed 2 years ago

tobyych commented 2 years ago
  1. What versions are you using?

platform.platform: Linux-5.10.60.1-microsoft-standard-WSL2-x86_64-with-glibc2.29 sys.maxsize > 2**32: True platform.python_version: 3.8.10 oracledb.version: 1.0.3

  1. Is it an error or a hang or a crash?

There is a message in console reading "Exception ignored".

  1. What error(s) or behavior you are seeing?
...
...
Exception ignored in: <function Connection.__del__ at 0x7f5a0eb16280>
Traceback (most recent call last):
  File "/home/toby/projects/mai/.venv/lib/python3.8/site-packages/oracledb/connection.py", line 144, in __del__
  File "src/oracledb/impl/thin/connection.pyx", line 283, in oracledb.thin_impl.ThinConnImpl.close
AttributeError: 'NoneType' object has no attribute 'SSLError'
  1. Does your application call init_oracle_client()?

No, running Thin mode.

  1. Include a runnable Python script that shows the problem.

I'm running other's code and there is a little wrapper class as follows. I run a Flask app that connects to Oracle DB, and the message always shows when I do Ctrl+C to stop the process. I see this message occasionally otherwise, but not sure about the root cause.

import oracledb as cx_Oracle

class OracleDB(object):
    def __init__(self, connection_str):
        self.con = cx_Oracle.connect(
            self.connection_str, encoding="UTF-8", nencoding="UTF-8", threaded=True
        )
        self.cursor = None
        self.cursor2 = None

    # some other methods here...

    def close(self):
        logger.info("closing db connection...")
        try:
            self.cursor.close()
            del self.cursor
        except:
            pass

        try:
            self.cursor2.close()
            del self.cursor2
        except:
            pass

        try:
            self.con.close()
            del self.con
        except:
            pass
cjbj commented 2 years ago

At a Ctrl-C, I can imagine some internal state is in flux, but maybe we can improve something there.

But what do you mean 'occasionally otherwise'? That doesn't sound nice. Would you be able to enable some tracing? See https://python-oracledb.readthedocs.io/en/latest/user_guide/tracing.html#low-level-python-oracledb-driver-tracing

anthony-tuininga commented 2 years ago

I did some searching and it looks like this issue is due to interpreter shutdown and the fact that in some cases, module globals are set to the value None which prevents this code from running properly. This issue has been resolved in most situations from Python 3.4 onwards, but you must have a case where that is not true! Since this is not something specific to python-oracledb only occurs during interpreter shutdown I will go ahead and close this. If you have more details on the environment and a test case that demonstrates the problem, feel free to re-open with that information and I'll take another look.