import asyncio import aiopg sa import logging import cfg asyncio corou

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import asyncio
import aiopg.sa
import logging
import cfg
@asyncio.coroutine
def create_engine():
engine = yield from aiopg.sa.create_engine(cfg.SQLALCHEMY_DATABASE_URI)
return engine
loop = asyncio.get_event_loop()
engine = loop.run_until_complete(create_engine())
from models import Base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine as create_engine_synchroneous
sengine = create_engine_synchroneous(cfg.SQLALCHEMY_DATABASE_URI)
Base.metadata.create_all(sengine)
logger = logging.getLogger(__name__)
logger.info(engine.__dict__)
logger.info(sengine.__dict__)
Session = sessionmaker(bind=engine)
"""
Traceback (most recent call last):
File "/site-packages/aiorest/server.py", line 147, in dispatch
ret = handler(request)
File "/projects/my/handlers.py", line 18, in sqla
session.commit()
File "/site-packages/sqlalchemy/orm/session.py", line 776, in commit
self.transaction.commit()
File "/site-packages/sqlalchemy/orm/session.py", line 377, in commit
self._prepare_impl()
File "/site-packages/sqlalchemy/orm/session.py", line 357, in _prepare_impl
self.session.flush()
File "/site-packages/sqlalchemy/orm/session.py", line 1919, in flush
self._flush(objects)
File "/site-packages/sqlalchemy/orm/session.py", line 2037, in _flush
transaction.rollback(_capture_exception=True)
File "/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/site-packages/sqlalchemy/util/compat.py", line 182, in reraise
raise value
File "/site-packages/sqlalchemy/orm/session.py", line 2001, in _flush
flush_context.execute()
File "/site-packages/sqlalchemy/orm/unitofwork.py", line 372, in execute
rec.execute(self)
File "/site-packages/sqlalchemy/orm/unitofwork.py", line 526, in execute
uow
File "/site-packages/sqlalchemy/orm/persistence.py", line 46, in save_obj
uowtransaction)
File "/site-packages/sqlalchemy/orm/persistence.py", line 141, in _organize_states_for_save
states):
File "/site-packages/sqlalchemy/orm/persistence.py", line 849, in _connections_for_states
base_mapper)
File "/site-packages/sqlalchemy/orm/session.py", line 232, in connection
return self._connection_for_bind(bind)
File "/site-packages/sqlalchemy/orm/session.py", line 311, in _connection_for_bind
conn = self._parent._connection_for_bind(bind)
File "/site-packages/sqlalchemy/orm/session.py", line 322, in _connection_for_bind
conn = bind.contextual_connect()
AttributeError: 'Engine' object has no attribute 'contextual_connect'
"""