python-oracledb icon indicating copy to clipboard operation
python-oracledb copied to clipboard

Consider making `check_and_return_mode` public

Open CaselIT opened this issue 3 years ago • 5 comments

  1. Describe your new request in detail

I think it would be useful to have a way of finding the mode of the oracledb library without having to connect to the db to execute the suggested https://python-oracledb.readthedocs.io/en/latest/user_guide/tracing.html#vsessconinfo

Looking at the library it seems that there is an internal function check_and_return_mode that returns this information. Given its returning value also a simpler wrapper called something like def is_thin_mode()->bool: ... would be enough

  1. Give supporting information about tools and operating systems. Give relevant product version numbers

n/a

CaselIT avatar Jun 03 '22 19:06 CaselIT

There's a much simpler way to find out. Does this work for you?

conn = oracledb.connect(user="my_user", password="my_password", dsn="my_host/my_service_name")
print("I am thin?", conn.thin)

Note that the mode of the driver is undefined until either a connection is established or a call to init_oracle_client() is made. So a simple boolean would be insufficient. Thoughts?

anthony-tuininga avatar Jun 03 '22 20:06 anthony-tuininga

I guess that could work yes. My current use case is marking some tests as expect failure in the sqlalchemy if the driver is in thin mode (mainly two-phase commit that's not supported), so I could make a method in the sqlalchemy driver that accepts a connection and returns that information.

Thanks for the quick response, I think we can close. It may just make sense to mention the thin attribute in this section https://python-oracledb.readthedocs.io/en/latest/user_guide/tracing.html#vsessconinfo ?

CaselIT avatar Jun 03 '22 20:06 CaselIT

I agree that the documentation should mention that information, too. I think the intent of that section was for someone tracing from the SQL side of things, not Python -- but let's see what @cjbj thinks.

anthony-tuininga avatar Jun 03 '22 20:06 anthony-tuininga

Sometimes I praise myself for foresight about what will be useful.... (which wipes out memory of all the things I predicted incorrectly). I knew a flag would be useful, and mentioned it more than once! We should add a python-oracledb boolean to indicate the mode - I would argue strongly that the initial state is 'Thin', not undefined. Just like any state flag the value can change during an app's life. Yes at some point in python-oracledb it will become unchangeable, but that's not important.

Regarding doc, towards the end of the 1.0.0 development phase the tracing.html section morphed into a general tracing section so it makes sense to mention connection.thin and pool.thin.

cjbj avatar Jun 03 '22 21:06 cjbj

I've added the necessary code. This is the documentation for the new method:

oracledb.is_thin_mode()

    Returns a boolean indicating if Thin mode is in use.

    Immediately after python-oracledb is imported, this function will return
    True indicating that python-oracledb defaults to Thin mode. If
    oracledb.init_oracle_client() is called, then a subsequent call to
    is_thin_mode() will return False indicating that Thick mode is
    enabled. Once the first standalone connection or connection pool is
    created, or a call to oracledb.init_oracle_client() is made, then
    python-oracledb’s mode is fixed and the value returned by
    is_thin_mode() will never change for the lifetime of the process.

    The attribute Connection.thin can be used to check a connection's
    mode.

anthony-tuininga avatar Jul 12 '22 16:07 anthony-tuininga

This enhancement has been implemented in python-oracledb 1.1.0 which was just released.

anthony-tuininga avatar Sep 14 '22 16:09 anthony-tuininga

thanks!

CaselIT avatar Sep 14 '22 19:09 CaselIT