pool_pre_ping not a valid kwarg for create_engine for MySQL

Issue #4039 resolved
Heather Lent created an issue

I am on the most up-to-date SQLAlchemy (1.1.12), and trying to use the pool_pre_ping=True in the create_engine() function. Attempting to use pool_pre_ping results in an error, that pool_pre_ping is not a valid keyword argument.

Here is a test that anyone can run to re-create the problem. Instructions for needed dependencies, my version of MySQL, and my driver are in the comments at the top of the code. You will need to replace "mysql://...." with the credentials for your own database.

'''
Setup instructions for Python 3.4 or 3.5 (will probably work for any version of 3):
pip install sqlalchemy=='1.1.12'
pip install mysqlclient #database driver; necessary for MySQL & sqlalchemy for Python 3 

I have MySQL version 5.6.33 on Ubuntu 14.04
'''
from sqlalchemy import create_engine #import create_engine

engine = create_engine("mysql://username:password@localhost:port/dbname?charset=utf8mb4", pool_pre_ping=True) #attempt to create engine

'''
FULL STACK TRACE ERROR: 
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    engine = create_engine("mysql://username:password@localhost:port/dbname?charset=utf8mb4", pool_pre_ping=True)
  File "/home/hclent/anaconda3/lib/python3.5/site-packages/sqlalchemy/engine/__init__.py", line 387, in create_engine
    return strategy.create(*args, **kwargs)
  File "/home/hclent/anaconda3/lib/python3.5/site-packages/sqlalchemy/engine/strategies.py", line 160, in create
    engineclass.__name__))
TypeError: Invalid argument(s) 'pool_pre_ping' sent to create_engine(), using configuration MySQLDialect_mysqldb/QueuePool/Engine.  Please check that the keyword arguments are appropriate for this combination of components.
'''

I have attached this code in a .py file as well. Running it will show the error just as I have documented it (but make sure to follow the setup instructions!)

Other comments:

If I navigate to the directory where SQLALchemy files are .../lib/python3.5/site-packages/sqlalchemy, and try: grep -r pool_pre_ping * | less There are no results, suggesting that pool_pre_ping is not actually valid for the stable release of sqlalchemy. I also checked the __init__.py in sqlalchemy/engine, where the create_engine( ) function lives, and it does not mention pool_pre_ping anywhere.

According to this documentation, create_engine(..., pool_pre_ping=True) should not fail. Since I am using MySQL and need a reliable connection pool for many users, disabling the pool as suggested in Issue 3919 and spelled out here is not a good alternative.

That being said, the release of 1.2.0b1 seems to have a bugfix that would allow me to do create_engine.pool_pre_ping( ... ). Does this mean I should be using an unstable version of SQLAlchemy?

In summary, given the documentation, the fact I'm using SQLAlchemy 1.1.12, I believe that there is a bug here.

Please let me know if I am missing anything in my Issue (I believe I properly followed the guidelines) and if there's any way I can help contribute :)

Comments (3)

  1. Mike Bayer repo owner

    the link to the documentation you've given is SQLAlchemy 1.2 documentation, e.g. the "latest". If you click on pool_pre_ping you go here: http://docs.sqlalchemy.org/en/latest/core/engines.html#sqlalchemy.create_engine.params.pool_pre_ping where you can see "New in version 1.2".

    For 1.1-only documentation you'd want to use the dropdown at the top of the site "library -> Reference -> Version 1.1". In that version, there is a recipe using an event listener that accomplishes the same general behavior as that of pool_pre_ping.

  2. Mike Bayer repo owner

    Also thanks for all the detail, as you may imagine the majority of users don't bother to tell me anything about what their problem is, however in this case it wasn't really necessary.... feel free to use the mailing list for quick questions where you can just get an answer and whether or not we need to see a test case.

  3. Mike Bayer repo owner

    I've established server-side rendering for version-specific banners and for "latest" there is now a red PRE RELEASE banner on the persistent sidebar, now that a server-side token is present I can add more graphical elements based on this as well going forward.

  4. Log in to comment