P
P
Pavel2018-02-16 16:49:07
Flask
Pavel, 2018-02-16 16:49:07

What does this psycopg2 allow itself?

def create_app(config_object=ProdConfig):
    """
    :param config_object: The configuration object to use.
    """
    app = Flask(__name__.split('.')[0])
    app.config.from_object(config_object)
    register_logger(app)
    register_extensions(app)
    register_blueprints(app)
    register_dynamic_preference(app, db) # ПРОБЛЕМА ТУТ
    register_errorhandlers(app)
    register_shellcontext(app)
    register_commands(app)

def register_dynamic_preference(app, db):
    """Register dynamic preference"""
    from appdata.dashboard.models import Preference
    preference_table_name = 'preference'
    with app.app_context():
        if not preference_table_name in [t.name for t in db.metadata.sorted_tables]:
            app.logger.exception('Table PREFERENCE not exists')
            return

        if app.config['DYNAMIC_PREFERENCES']:
            for k, data in app.config['DYNAMIC_PREFERENCES'].items():
                if not Preference.exists(k):
                    Preference.add(k, data['default_value'])
        else:
            app.logger.exception('DYNAMIC_PREFERENCES not available')


After that, Celery stops communicating with the database

Traceback (most recent call last):
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 701, in _rollback_impl
celery_high_1 | self.engine.dialect.do_rollback(self.connection)
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 440, in do_rollback
celery_high_1 | dbapi_connection.rollback()
celery_high_1 | psycopg2.DatabaseError: error with status PGRES_TUPLES_OK and no message from the libpq
celery_high_1 |
celery_high_1 | The above exception was the direct cause of the following exception:
celery_high_1 |
celery_high_1 | Traceback (most recent call last):
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/pool.py", line 687, in _finalize_fairy
celery_high_1 | fairy._reset(pool)
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/pool.py", line 827, in _reset
celery_high_1 | self._reset_agent.rollback()
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1621, in rollback
celery_high_1 | self._do_rollback()
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1659, in _do_rollback
celery_high_1 | self.connection._rollback_impl()
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 703, in _rollback_impl
celery_high_1 | self._handle_dbapi_exception(e, None, None, None, None)
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception
celery_high_1 | exc_info
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
celery_high_1 | reraise(type(exception), exception, tb=exc_tb, cause=cause)
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 186, in reraise
celery_high_1 | raise value.with_traceback(tb)
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 701, in _rollback_impl
celery_high_1 | self.engine.dialect.do_rollback(self.connection)
celery_high_1 | File "/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 440, in do_rollback
celery_high_1 | dbapi_connection.rollback()
celery_high_1 | sqlalchemy.exc.DatabaseError: (psycopg2.DatabaseError) error with status PGRES_TUPLES_OK and no message from the libpq


If register_dynamic_preference is not called from create_app, then everything is fine.
Why and how to fix?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question