Skip to content
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

cx_oracle throws "DPI-1054: connection cannot be closed when open statements or LOBs exist" during django migration #138

Closed
alfa0ne opened this issue Jan 23, 2018 · 11 comments

Comments

@alfa0ne
Copy link

alfa0ne commented Jan 23, 2018

I have connected remote Oracle 9i DB with OCI version 11.2 in my window 7. Connection works fine, but when I run django manage.py migrate command I get DPI-1054: connection cannot be closed when open statements or LOBs exist
Environment :
Python3.6
Django1.11.9
cx_Orcale6.0

Similar issue has been reported to ticket

@anthony-tuininga
Copy link
Member

We are currently investigating the possibility of eliminating this error completely by internally tracking the open statements and LOBs and closing them when connection.close() is called. You can work around the situation by simply avoiding the call to connection.close(). So long as there are no circular references the connection, statements and LOBs will close perfectly well without help!

anthony-tuininga added a commit that referenced this issue Jan 27, 2018
@anthony-tuininga
Copy link
Member

I just pushed a commit that removes this restriction and automatically closes statements and LOBs that are still open when the connection associated with them is closed. This will become part of 6.2 when it is released.

@alfa0ne
Copy link
Author

alfa0ne commented Jan 30, 2018

Tested the 6.2-dev build for the 9i DB. There is no reported error or exception. Worked all migrations.
Thanks 👍

@elewinso
Copy link

elewinso commented Feb 2, 2018

I am having the same issue with the following stack.
i cannot update the python version, is there a workaround?

tech stack:
1.
Oracle Database 12c EE Extreme Perf Release 12.2.0.1.
2.
cx driver cx_Oracle-6.1-cp27-cp27mu-manylinux1_x86_64.whl from https://pypi.python.org/pypi/cx_Oracle3.

  1. python version
    2.7.12 (default, Nov 20 2017, 18:23:56)
    [GCC 5.4.0 20160609]

@anthony-tuininga
Copy link
Member

As noted above, you can simply remove the call to connection.close() from within Django. The only other possibilities are to build cx_Oracle from the latest source or wait until 6.2 is released (hopefully in the next couple of weeks).

@elewinso
Copy link

elewinso commented Feb 4, 2018

Thank you Anthony, the thing is that I am merely running loaddata when this happens. I'm not sure what's the best place to call connection.close()
thanks

@cjbj
Copy link
Member

cjbj commented Feb 6, 2018

@elewinso the point is to NOT call connection.close(), but to let cx_Oracle clean up in a rational order.

@sushmit86
Copy link

Has this issue been fixed? I am still getting the error while using connection.close()

@anthony-tuininga
Copy link
Member

Yes, this has been fixed -- in version 6.2 as noted earlier in this thread!

@marcusbarbara
Copy link

Esse erro acontece quando é atribuído de forma direta o CLOB a uma variável, se atribuir a mesmo em uma variável, mais como texto, não acontece o erro.
Quando fecha a conexão ele entende que tem alguém lendo o objeto.

--- Errado ------------------- Objeto
cursor.execute( sql )
res = cursor.fetchall()
texto_clob = res[0][0]
cursor.close()
connection.close()

--- Correto ------------------- Texto
cursor.execute( sql )
res = cursor.fetchall()
texto_clob = str(res[0][0])
cursor.close()
connection.close()

@anthony-tuininga
Copy link
Member

anthony-tuininga commented Feb 25, 2019

Yes, the connection must remain open if you plan to process the LOB. If you call str() on it, that automatically gets its contents so the connection no longer needs to be open.

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

No branches or pull requests

6 participants