altairbow / django-db-connection-pool

Database connection pool component library for Django
https://pypi.python.org/pypi/django-db-connection-pool/
MIT License
181 stars 24 forks source link

save does not committing when using pool #33

Closed ftamy9 closed 1 year ago

ftamy9 commented 2 years ago

Thanks @altairbow , I have same problem. I can not save correctly. the program looks ok without error but the table is not update when I check it on django admin. It works ok when I use (('ENGINE': 'django.db.backends.oracle')) with out the pool.

Python3.8.10 + django 3.2 + Oracle 18C

'default': { 'ENGINE': 'dj_db_conn_pool.backends.oracle', 'POOL_OPTIONS': { 'POOL_SIZE': 10, 'MAX_OVERFLOW': 10, 'RECYCLE': 24 60 60, }, 'AUTOCOMMIT': True, 'NAME': 'xxx', 'USER': 'xxx', 'PASSWORD': 'xxx', }

Originally posted by @boscharun in https://github.com/altairbow/django-db-connection-pool/issues/5#issuecomment-494926473

kevin-kessler commented 2 years ago

Same issue here. Did you manage to solve the problem @ftamy9 ? Any idea @altairbow ?

Python 3.9, Django 3.2.7, Oracle 19

kevin-kessler commented 2 years ago

So it looks like the Oracle connections created with SQLAlchemy (which django-db-connection-pool is based on) have their autocommit flag set to 0 by default.

A quick test of setting the flag to 1 after the connection has been returned by the pool confirmed the assumption and Django started persisting my changes all of a sudden again.

I fixed it by implementing _set_autocommit in oracle/base.py and submitted a pullrequest here: https://github.com/altairbow/django-db-connection-pool/pull/35

altairbow commented 2 years ago

So it looks like the Oracle connections created with SQLAlchemy (which django-db-connection-pool is based on) have their autocommit flag set to 0 by default.

A quick test of setting the flag to 1 after the connection has been returned by the pool confirmed the assumption and Django started persisting my changes all of a sudden again.

I fixed it by implementing _set_autocommit in oracle/base.py and submitted a pullrequest here: #35

Great work! Thanks, PR has been merged, and version 1.2.0 has been released.

kevin-kessler commented 2 years ago

Great work! Thanks, PR has been merged, and version 1.2.0 has been released.

Perfect, thanks for the quick action!