tko22 / flask-boilerplate

Simple flask boilerplate with Postgres, Docker, and Heroku/Zeit now
https://github.com/tko22/flask-boilerplate/wiki
MIT License
301 stars 100 forks source link

sqlalchemy.exc.OperationalError in Docker setup #23

Closed BrandoZhang closed 5 years ago

BrandoZhang commented 5 years ago

Hi, thanks for your nice work!

When I clone this repo and run docker-compose up --build, I get the following error:

app         | /usr/local/lib/python3.7/site-packages/sqlalchemy/sql/functions.py:67: SAWarning: The GenericFunction 'array_agg' is already registered and is going to be overriden.
app         |   "is going to be overriden.".format(identifier)
app         | /usr/local/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
app         |   """)
app         | Traceback (most recent call last):
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2265, in _wrap_pool_connect
app         |     return fn()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 363, in connect
app         |     return _ConnectionFairy._checkout(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 760, in _checkout
app         |     fairy = _ConnectionRecord.checkout(pool)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
app         |     rec = pool._do_get()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 139, in _do_get
app         |     self._dec_overflow()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
app         |     compat.reraise(exc_type, exc_value, exc_tb)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 153, in reraise
app         |     raise value
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
app         |     return self._create_connection()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
app         |     return _ConnectionRecord(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
app         |     self.__connect(first_connect_check=True)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 639, in __connect
app         |     connection = pool._invoke_creator(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
app         |     return dialect.connect(*cargs, **cparams)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 453, in connect
app         |     return self.dbapi.connect(*cargs, **cparams)
app         |   File "/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py", line 130, in connect
app         |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
app         | psycopg2.OperationalError: server closed the connection unexpectedly
app         |   This probably means the server terminated abnormally
app         |   before or while processing the request.
app         |
app         |
app         | The above exception was the direct cause of the following exception:
app         |
app         | Traceback (most recent call last):
app         |   File "manage.py", line 7, in <module>
app         |     app = create_app()
app         |   File "/app/api/__init__.py", line 71, in create_app
app         |     if not database_exists(db_url):
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy_utils/functions/database.py", line 472, in database_exists
app         |     return bool(get_scalar_result(engine, text))
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy_utils/functions/database.py", line 455, in get_scalar_result
app         |     result_proxy = engine.execute(sql)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2168, in execute
app         |     connection = self._contextual_connect(close_with_result=True)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2229, in _contextual_connect
app         |     self._wrap_pool_connect(self.pool.connect, None),
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2269, in _wrap_pool_connect
app         |     e, dialect, self
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1536, in _handle_dbapi_exception_noconnection
app         |     util.raise_from_cause(sqlalchemy_exception, exc_info)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
app         |     reraise(type(exception), exception, tb=exc_tb, cause=cause)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 152, in reraise
app         |     raise value.with_traceback(tb)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2265, in _wrap_pool_connect
app         |     return fn()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 363, in connect
app         |     return _ConnectionFairy._checkout(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 760, in _checkout
app         |     fairy = _ConnectionRecord.checkout(pool)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
app         |     rec = pool._do_get()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 139, in _do_get
app         |     self._dec_overflow()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
app         |     compat.reraise(exc_type, exc_value, exc_tb)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 153, in reraise
app         |     raise value
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
app         |     return self._create_connection()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
app         |     return _ConnectionRecord(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
app         |     self.__connect(first_connect_check=True)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 639, in __connect
app         |     connection = pool._invoke_creator(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
app         |     return dialect.connect(*cargs, **cparams)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 453, in connect
app         |     return self.dbapi.connect(*cargs, **cparams)
app         |   File "/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py", line 130, in connect
app         |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
app         | sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly
app         |   This probably means the server terminated abnormally
app         |   before or while processing the request.
app         |
app         | (Background on this error at: http://sqlalche.me/e/e3q8)
app         | /usr/local/lib/python3.7/site-packages/sqlalchemy/sql/functions.py:67: SAWarning: The GenericFunction 'array_agg' is already registered and is going to be overriden.
app         |   "is going to be overriden.".format(identifier)
app         | /usr/local/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
app         |   """)
app         | Traceback (most recent call last):
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2265, in _wrap_pool_connect
app         |     return fn()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 363, in connect
app         |     return _ConnectionFairy._checkout(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 760, in _checkout
app         |     fairy = _ConnectionRecord.checkout(pool)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
app         |     rec = pool._do_get()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 139, in _do_get
app         |     self._dec_overflow()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
app         |     compat.reraise(exc_type, exc_value, exc_tb)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 153, in reraise
app         |     raise value
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
app         |     return self._create_connection()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
app         |     return _ConnectionRecord(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
app         |     self.__connect(first_connect_check=True)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 639, in __connect
app         |     connection = pool._invoke_creator(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
app         |     return dialect.connect(*cargs, **cparams)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 453, in connect
app         |     return self.dbapi.connect(*cargs, **cparams)
app         |   File "/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py", line 130, in connect
app         |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
app         | psycopg2.OperationalError: server closed the connection unexpectedly
app         |   This probably means the server terminated abnormally
app         |   before or while processing the request.
app         |
app         |
app         | The above exception was the direct cause of the following exception:
app         |
app         | Traceback (most recent call last):
app         |   File "manage.py", line 7, in <module>
app         |     app = create_app()
app         |   File "/app/api/__init__.py", line 71, in create_app
app         |     if not database_exists(db_url):
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy_utils/functions/database.py", line 472, in database_exists
app         |     return bool(get_scalar_result(engine, text))
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy_utils/functions/database.py", line 455, in get_scalar_result
app         |     result_proxy = engine.execute(sql)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2168, in execute
app         |     connection = self._contextual_connect(close_with_result=True)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2229, in _contextual_connect
app         |     self._wrap_pool_connect(self.pool.connect, None),
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2269, in _wrap_pool_connect
app         |     e, dialect, self
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1536, in _handle_dbapi_exception_noconnection
app         |     util.raise_from_cause(sqlalchemy_exception, exc_info)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
app         |     reraise(type(exception), exception, tb=exc_tb, cause=cause)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 152, in reraise
app         |     raise value.with_traceback(tb)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2265, in _wrap_pool_connect
app         |     return fn()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 363, in connect
app         |     return _ConnectionFairy._checkout(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 760, in _checkout
app         |     fairy = _ConnectionRecord.checkout(pool)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
app         |     rec = pool._do_get()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 139, in _do_get
app         |     self._dec_overflow()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
app         |     compat.reraise(exc_type, exc_value, exc_tb)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 153, in reraise
app         |     raise value
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
app         |     return self._create_connection()
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
app         |     return _ConnectionRecord(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
app         |     self.__connect(first_connect_check=True)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 639, in __connect
app         |     connection = pool._invoke_creator(self)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
app         |     return dialect.connect(*cargs, **cparams)
app         |   File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 453, in connect
app         |     return self.dbapi.connect(*cargs, **cparams)
app         |   File "/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py", line 130, in connect
app         |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
app         | sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly
app         |   This probably means the server terminated abnormally
app         |   before or while processing the request.
app         |
app         | (Background on this error at: http://sqlalche.me/e/e3q8)

Any idea?

BrandoZhang commented 5 years ago

Sorry, it's my fault. After undo my change in docker-compose.yml from

image: postgres:11

to

image: postgres:10

and it works...