In [1]:
import sys
app_path = '/data/app/app'
if sys.path[0] != app_path:
    sys.path.insert(0, app_path)

In [2]:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

In [ ]:


In [ ]:


In [3]:
import app

In [4]:
print(app.app.config['SQLALCHEMY_DATABASE_URI'])


postgresql://postgres:password@db/flask-app

In [5]:
db = SQLAlchemy(app.app)

In [6]:
from sqlalchemy.sql import text

In [7]:
stmt = text("SELECT 1")
conn = db.engine.connect()


---------------------------------------------------------------------------
Empty                                     Traceback (most recent call last)
/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in _do_get(self)
   1043             wait = use_overflow and self._overflow >= self._max_overflow
-> 1044             return self._pool.get(wait, self._timeout)
   1045         except sqla_queue.Empty:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/util/queue.py in get(self, block, timeout)
    144                 if self._empty():
--> 145                     raise Empty
    146             elif timeout is None:

Empty: 

During handling of the above exception, another exception occurred:

OperationalError                          Traceback (most recent call last)
/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/base.py in _wrap_pool_connect(self, fn, connection)
   2073         try:
-> 2074             return fn()
   2075         except dialect.dbapi.Error as e:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in unique_connection(self)
    317         """
--> 318         return _ConnectionFairy._checkout(self)
    319 

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in _checkout(cls, pool, threadconns, fairy)
    712         if not fairy:
--> 713             fairy = _ConnectionRecord.checkout(pool)
    714 

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in checkout(cls, pool)
    479     def checkout(cls, pool):
--> 480         rec = pool._do_get()
    481         try:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in _do_get(self)
   1059                     with util.safe_reraise():
-> 1060                         self._dec_overflow()
   1061             else:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/util/langhelpers.py in __exit__(self, type_, value, traceback)
     59             self._exc_info = None   # remove potential circular references
---> 60             compat.reraise(exc_type, exc_value, exc_tb)
     61         else:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/util/compat.py in reraise(tp, value, tb, cause)
    185             raise value.with_traceback(tb)
--> 186         raise value
    187 

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in _do_get(self)
   1056                 try:
-> 1057                     return self._create_connection()
   1058                 except:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in _create_connection(self)
    322 
--> 323         return _ConnectionRecord(self)
    324 

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in __init__(self, pool)
    448         self.__pool = pool
--> 449         self.connection = self.__connect()
    450         self.finalize_callback = deque()

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in __connect(self)
    606             self.starttime = time.time()
--> 607             connection = self.__pool._invoke_creator(self)
    608             self.__pool.logger.debug("Created new connection %r", connection)

/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/strategies.py in connect(connection_record)
     96                             return connection
---> 97                 return dialect.connect(*cargs, **cparams)
     98 

/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/default.py in connect(self, *cargs, **cparams)
    384     def connect(self, *cargs, **cparams):
--> 385         return self.dbapi.connect(*cargs, **cparams)
    386 

/opt/conda/lib/python3.5/site-packages/psycopg2/__init__.py in connect(dsn, database, user, password, host, port, connection_factory, cursor_factory, async, **kwargs)
    163 
--> 164     conn = _connect(dsn, connection_factory=connection_factory, async=async)
    165     if cursor_factory is not None:

OperationalError: FATAL:  database "flask-app" does not exist


The above exception was the direct cause of the following exception:

OperationalError                          Traceback (most recent call last)
<ipython-input-7-a04ac1681df5> in <module>()
      1 stmt = text("SELECT 1")
----> 2 conn = db.engine.connect()

/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/base.py in connect(self, **kwargs)
   2016         """
   2017 
-> 2018         return self._connection_cls(self, **kwargs)
   2019 
   2020     def contextual_connect(self, close_with_result=False, **kwargs):

/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/base.py in __init__(self, engine, connection, close_with_result, _branch_from, _execution_options, _dispatch, _has_events)
     70         else:
     71             self.__connection = connection \
---> 72                 if connection is not None else engine.raw_connection()
     73             self.__transaction = None
     74             self.__savepoint_seq = 0

/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/base.py in raw_connection(self, _connection)
   2102         """
   2103         return self._wrap_pool_connect(
-> 2104             self.pool.unique_connection, _connection)
   2105 
   2106 

/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/base.py in _wrap_pool_connect(self, fn, connection)
   2076             if connection is None:
   2077                 Connection._handle_dbapi_exception_noconnection(
-> 2078                     e, dialect, self)
   2079             else:
   2080                 util.reraise(*sys.exc_info())

/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/base.py in _handle_dbapi_exception_noconnection(cls, e, dialect, engine)
   1403             util.raise_from_cause(
   1404                 sqlalchemy_exception,
-> 1405                 exc_info
   1406             )
   1407         else:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/util/compat.py in raise_from_cause(exception, exc_info)
    200     exc_type, exc_value, exc_tb = exc_info
    201     cause = exc_value if exc_value is not exception else None
--> 202     reraise(type(exception), exception, tb=exc_tb, cause=cause)
    203 
    204 if py3k:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/util/compat.py in reraise(tp, value, tb, cause)
    183             value.__cause__ = cause
    184         if value.__traceback__ is not tb:
--> 185             raise value.with_traceback(tb)
    186         raise value
    187 

/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/base.py in _wrap_pool_connect(self, fn, connection)
   2072         dialect = self.dialect
   2073         try:
-> 2074             return fn()
   2075         except dialect.dbapi.Error as e:
   2076             if connection is None:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in unique_connection(self)
    316 
    317         """
--> 318         return _ConnectionFairy._checkout(self)
    319 
    320     def _create_connection(self):

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in _checkout(cls, pool, threadconns, fairy)
    711     def _checkout(cls, pool, threadconns=None, fairy=None):
    712         if not fairy:
--> 713             fairy = _ConnectionRecord.checkout(pool)
    714 
    715             fairy._pool = pool

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in checkout(cls, pool)
    478     @classmethod
    479     def checkout(cls, pool):
--> 480         rec = pool._do_get()
    481         try:
    482             dbapi_connection = rec.get_connection()

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in _do_get(self)
   1058                 except:
   1059                     with util.safe_reraise():
-> 1060                         self._dec_overflow()
   1061             else:
   1062                 return self._do_get()

/opt/conda/lib/python3.5/site-packages/sqlalchemy/util/langhelpers.py in __exit__(self, type_, value, traceback)
     58             exc_type, exc_value, exc_tb = self._exc_info
     59             self._exc_info = None   # remove potential circular references
---> 60             compat.reraise(exc_type, exc_value, exc_tb)
     61         else:
     62             if not compat.py3k and self._exc_info and self._exc_info[1]:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/util/compat.py in reraise(tp, value, tb, cause)
    184         if value.__traceback__ is not tb:
    185             raise value.with_traceback(tb)
--> 186         raise value
    187 
    188 else:

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in _do_get(self)
   1055             if self._inc_overflow():
   1056                 try:
-> 1057                     return self._create_connection()
   1058                 except:
   1059                     with util.safe_reraise():

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in _create_connection(self)
    321         """Called by subclasses to create a new ConnectionRecord."""
    322 
--> 323         return _ConnectionRecord(self)
    324 
    325     def _invalidate(self, connection, exception=None):

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in __init__(self, pool)
    447     def __init__(self, pool):
    448         self.__pool = pool
--> 449         self.connection = self.__connect()
    450         self.finalize_callback = deque()
    451 

/opt/conda/lib/python3.5/site-packages/sqlalchemy/pool.py in __connect(self)
    605         try:
    606             self.starttime = time.time()
--> 607             connection = self.__pool._invoke_creator(self)
    608             self.__pool.logger.debug("Created new connection %r", connection)
    609             return connection

/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/strategies.py in connect(connection_record)
     95                         if connection is not None:
     96                             return connection
---> 97                 return dialect.connect(*cargs, **cparams)
     98 
     99             creator = pop_kwarg('creator', connect)

/opt/conda/lib/python3.5/site-packages/sqlalchemy/engine/default.py in connect(self, *cargs, **cparams)
    383 
    384     def connect(self, *cargs, **cparams):
--> 385         return self.dbapi.connect(*cargs, **cparams)
    386 
    387     def create_connect_args(self, url):

/opt/conda/lib/python3.5/site-packages/psycopg2/__init__.py in connect(dsn, database, user, password, host, port, connection_factory, cursor_factory, async, **kwargs)
    162                 for (k, v) in items])
    163 
--> 164     conn = _connect(dsn, connection_factory=connection_factory, async=async)
    165     if cursor_factory is not None:
    166         conn.cursor_factory = cursor_factory

OperationalError: (psycopg2.OperationalError) FATAL:  database "flask-app" does not exist

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: