Skip to content

Unexpected behaviour of __exit__ method #113

@aalloul

Description

@aalloul

Description:

I believe the __exit__() method does not behave as expected. PEP-343 states

Many context managers (such as files and generator-based contexts) will be single-use objects. Once the __exit__() method has been called, the context manager will no longer be in a usable state (e.g. the file has been closed, or the underlying generator has finished execution).

The current implementation commits or rolls-back any transaction but leaves the connection open.

More information

  1. What is your version of Python? Is it 32-bit or 64-bit?
    Python 3.6, 64 bits

  2. What is your version of cx_Oracle?
    '6.0b2'

  3. What is your OS and version?
    Mac OSX 10.12.6

  4. What compiler version did you use? For example, with GCC, run
    gcc --version.
    Apple LLVM version 9.0.0 (clang-900.0.38)

  5. What exact command caused the problem (e.g. what command did you try to
    install with)? Who were you logged in as?
    conn= cx_Oracle.connect(user=username,password=password,dsn=dsn) conn.__exit__()

  6. What error(s) you are seeing?
    The __exit__() method returns False without closing the connection. This is unexpected behaviour as users usually expect a with-block to always close the open connection. As an example,

f = open(filename, "r")
f.__exit__()
f.closed

returns True

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions