New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anyblok_createdb on postgresql+psycopg2ffi #74

Open
gracinet opened this Issue Nov 28, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@gracinet
Copy link
Contributor

gracinet commented Nov 28, 2018

I was trying to play with the tests of Anyblok / WMS Base under PyPy, with the psycopg2cffi backend, and got an error (see the traceback below). Not sure if this should be reported as a difference in behaviour to psycopg2cffi folks or not…

My versions:

(pypyenv) ~/anyblok/wms/awb $ python --version
Python 3.5.3 (fdd60ed87e941677e8ea11acf9f1819466521bf2, Nov 28 2018, 12:39:44)
[PyPy 6.0.0 with GCC 6.3.0 20170516]
(pypyenv) ~/anyblok/wms/awb $ pip freeze | grep psyco
psycopg2cffi==2.8.1
Traceback (most recent call last):
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
    context)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute
    cursor.execute(statement, parameters)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/psycopg2cffi/_impl/cursor.py", line 30, in check_closed_
    return func(self, *args, **kwargs)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/psycopg2cffi/_impl/cursor.py", line 263, in execute
    self._pq_execute(self._query, conn._async)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/psycopg2cffi/_impl/cursor.py", line 696, in _pq_execute
    self._pq_fetch()
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/psycopg2cffi/_impl/cursor.py", line 757, in _pq_fetch
    raise self._conn._create_exception(cursor=self)
psycopg2cffi._impl.exceptions.InternalError: CREATE DATABASE cannot run inside a transaction block



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

Traceback (most recent call last):
  File "/home/gracinet/anyblok/wms/pypyenv/bin/anyblok_createdb", line 11, in <module>
    sys.exit(anyblok_createdb())
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/anyblok/scripts.py", line 95, in anyblok_createdb
    create_database(url, template=db_template_name)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy_utils/functions/database.py", line 559, in create_database
    result_proxy = engine.execute(text)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/engine/base.py", line 2075, in execute
    return connection.execute(statement, *multiparams, **params)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/engine/base.py", line 942, in execute
    return self._execute_text(object, multiparams, params)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/engine/base.py", line 1104, in _execute_text
    statement, parameters
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/engine/base.py", line 1200, in _execute_context
    context)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception
    exc_info
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/util/compat.py", line 265, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/util/compat.py", line 248, in reraise
    raise value.with_traceback(tb)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
    context)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute
    cursor.execute(statement, parameters)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/psycopg2cffi/_impl/cursor.py", line 30, in check_closed_
    return func(self, *args, **kwargs)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/psycopg2cffi/_impl/cursor.py", line 263, in execute
    self._pq_execute(self._query, conn._async)
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/psycopg2cffi/_impl/cursor.py", line 696, in _pq_execute
    self._pq_fetch()
  File "/home/gracinet/anyblok/wms/pypyenv/site-packages/psycopg2cffi/_impl/cursor.py", line 757, in _pq_fetch
    raise self._conn._create_exception(cursor=self)
sqlalchemy.exc.InternalError: (psycopg2cffi._impl.exceptions.InternalError) CREATE DATABASE cannot run inside a transaction block
 [SQL: 'CREATE DATABASE "test_awb_anyblok_wms_base.core" ENCODING \'utf8\' TEMPLATE template1'] (Background on this error at: http://sqlalche.me/e/2j85)

Apart from that, you'll be probably glad to hear that all the tests pass, provided I run anyblok_createdb first with the regular CPython / Psycopg2 stack.

@jssuzanne jssuzanne added this to the 1.0.0 milestone Nov 28, 2018

@jssuzanne jssuzanne self-assigned this Nov 28, 2018

@jssuzanne jssuzanne added the bug label Nov 28, 2018

gracinet added a commit to gracinet/anyblok_wms_base that referenced this issue Nov 29, 2018

run_all_tests: fixing launch on psycopg2cffi
Since anyblok_createdb doesn't work on all drivers,
we avoid it in favour of a psql call.
See also AnyBlok/AnyBlok#74
@gracinet

This comment has been minimized.

Copy link
Contributor Author

gracinet commented Nov 29, 2018

The problem actually lies in sqlalchemy_utils. anyblok_createdb doesn't do anything else than call its create_database.

gracinet added a commit to gracinet/anyblok_wms_base that referenced this issue Nov 29, 2018

run_all_tests: fixing launch on psycopg2cffi
Since anyblok_createdb doesn't work on all drivers,
we avoid it in favour of a psql call.
See also AnyBlok/AnyBlok#74
@jssuzanne

This comment has been minimized.

Copy link
Member

jssuzanne commented Nov 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment