<p dir="auto"><strong>Migrated issue, originally created by Michael Bayer (<a href="https://github.com/zzzeek">@zzzeek</a>)</strong></p>
<p dir="auto">When a pool can't connect to the DB, Python 3 does this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!

Traceback (most recent call last):
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py&quot;, line 1122, in _do_get
    return self._pool.get(wait, self._timeout)
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/util/queue.py&quot;, line 145, in get
    raise Empty
sqlalchemy.util.queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/engine/base.py&quot;, line 2147, in _wrap_pool_connect
    return fn()
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py&quot;, line 328, in unique_connection
    return _ConnectionFairy._checkout(self)
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py&quot;, line 766, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py&quot;, line 516, in checkout
    rec = pool._do_get()
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py&quot;, line 1138, in _do_get
    self._dec_overflow()
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 66, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/util/compat.py&quot;, line 187, in reraise
    raise value
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py&quot;, line 1135, in _do_get
    return self._create_connection()
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py&quot;, line 333, in _create_connection
    return _ConnectionRecord(self)
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py&quot;, line 461, in __init__
    self.__connect(first_connect_check=True)
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py&quot;, line 651, in __connect
    connection = pool._invoke_creator(self)
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/engine/strategies.py&quot;, line 105, in connect
    return dialect.connect(*cargs, **cparams)
  File &quot;/usr/local/lib64/python3.5/site-packages/sqlalchemy/engine/default.py&quot;, line 393, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File &quot;/usr/local/lib64/python3.5/site-packages/MySQLdb/__init__.py&quot;, line 81, in Connect
    return Connection(*args, **kwargs)
  File &quot;/usr/local/lib64/python3.5/site-packages/MySQLdb/connections.py&quot;, line 191, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, &quot;Can't connect to MySQL server on 'dbhost_obviously' (4)&quot;)"><pre class="notranslate"><code class="notranslate">#!

Traceback (most recent call last):
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py", line 1122, in _do_get
    return self._pool.get(wait, self._timeout)
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/util/queue.py", line 145, in get
    raise Empty
sqlalchemy.util.queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/engine/base.py", line 2147, in _wrap_pool_connect
    return fn()
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py", line 328, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py", line 766, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py", line 516, in checkout
    rec = pool._do_get()
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py", line 1138, in _do_get
    self._dec_overflow()
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/util/compat.py", line 187, in reraise
    raise value
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py", line 1135, in _do_get
    return self._create_connection()
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py", line 333, in _create_connection
    return _ConnectionRecord(self)
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py", line 461, in __init__
    self.__connect(first_connect_check=True)
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/pool.py", line 651, in __connect
    connection = pool._invoke_creator(self)
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/engine/strategies.py", line 105, in connect
    return dialect.connect(*cargs, **cparams)
  File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/engine/default.py", line 393, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/usr/local/lib64/python3.5/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/lib64/python3.5/site-packages/MySQLdb/connections.py", line 191, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'dbhost_obviously' (4)")
</code></pre></div>
<p dir="auto">this confuses everyone.  move the handling outside of Empty.</p>
<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">The code looks like this (skipping a log of details):</p>
<p dir="auto">class visit_dim_category(object):<br>
pass</p>
<p dir="auto">...</p>
<p dir="auto">class schema<br>
...</p>
<p dir="auto">#somewhere in class schema:</p>
<p dir="auto">self.visit_dim_category = Table( "visit_dim_category", self.metadata,<br>
Column("id",Integer, primary_key=True)<br>
,Column("affiliate", Integer, ForeignKey("affiliate.id"))<br>
,Column("product",   Integer, ForeignKey("product.id"))<br>
)</p>
<p dir="auto">Index("visit_dim_category_idx1",self.visit_dim_category.c.affiliate, self.visit_dim_category.c.product, unique=True)</p>
<p dir="auto">...</p>
<p dir="auto">visit_dim_category.mapper = mapper(visit_dim_category, self.visit_dim_category)</p>
<h2 dir="auto"></h2>
<p dir="auto">#creating test db<br>
db = create_engine(conf.connection())<br>
schema = schema(db)<br>
schema.metadata.drop_all()<br>
schema.metadata.create_all()</p>
<p dir="auto">it works fine in 0.2.7 and 0.2.8 but after updrade to 0.3 this code gives the following errors:</p>
<p dir="auto">[04:49 ]cff@joy:~/work/stats3/server/test# ./test_db.py<br>
create test schema...<br>
mysql://root:root@localhost/stat3<br>
Traceback (most recent call last):<br>
File "./test_db.py", line 15, in ?<br>
schema.metadata.create_all()<br>
File "build/bdist.linux-i686/egg/sqlalchemy/schema.py", line 862, in<br>
create_all<br>
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line<br>
413, in create<br>
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line<br>
437, in _run_visitor<br>
File "build/bdist.linux-i686/egg/sqlalchemy/schema.py", line 882, in<br>
accept_schema_visitor<br>
File "build/bdist.linux-i686/egg/sqlalchemy/ansisql.py", line 637,<br>
in visit_metadata<br>
File "build/bdist.linux-i686/egg/sqlalchemy/schema.py", line 268, in<br>
accept_schema_visitor<br>
File "build/bdist.linux-i686/egg/sqlalchemy/ansisql.py", line 671,<br>
in visit_table<br>
File "build/bdist.linux-i686/egg/sqlalchemy/schema.py", line 819, in<br>
accept_schema_visitor<br>
File "build/bdist.linux-i686/egg/sqlalchemy/ansisql.py", line 749,<br>
in visit_index<br>
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line<br>
763, in execute<br>
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line<br>
365, in proxy<br>
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line<br>
329, in _execute_raw<br>
File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line<br>
348, in _execute<br>
sqlalchemy.exceptions.SQLError: (OperationalError) (1061, "Duplicate<br>
key name 'visit_dim_category_idx1'") 'CREATE UNIQUE INDEX<br>
visit_dim_category_idx1 ON visit_dim_category (affiliate, product)' ()</p>