Skip to content

Commit 0a5b1f2

Browse files
David Jetelinajettify
authored andcommitted
Throw an exception when incompatible curos class is passed to SA engine (#272)
* Throw an exception when incompatible curos class is passed to SQLAlchemy engine * flake8 fix
1 parent 4409f2a commit 0a5b1f2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

aiomysql/sa/engine.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
import aiomysql
66
from .connection import SAConnection
7-
from .exc import InvalidRequestError
7+
from .exc import InvalidRequestError, ArgumentError
88
from ..utils import PY_35, _PoolContextManager, _PoolAcquireContextManager
9+
from ..cursors import Cursor
910

1011

1112
try:
@@ -28,6 +29,11 @@ def create_engine(minsize=1, maxsize=10, loop=None,
2829
"""
2930
coro = _create_engine(minsize=minsize, maxsize=maxsize, loop=loop,
3031
dialect=dialect, pool_recycle=pool_recycle, **kwargs)
32+
compatible_cursor_classes = [Cursor]
33+
# Without provided kwarg, default is default cursor from Connection class
34+
if kwargs.get('cursorclass', Cursor) not in compatible_cursor_classes:
35+
raise ArgumentError('SQLAlchemy engine does not support '
36+
'this cursor class')
3137
return _EngineContextManager(coro)
3238

3339

0 commit comments

Comments
 (0)