From: Gord Thompson Date: Thu, 3 Oct 2019 22:18:54 +0000 (-0400) Subject: fix error in test_round_trip for TimeTest with mysql+pyodbc X-Git-Tag: rel_1_3_10~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c6070ee79fbb15ebafbef2d2d37e93b49f8c9b0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix error in test_round_trip for TimeTest with mysql+pyodbc Fixes: #4879 ### Description create mysql+pyodbc-specific `_pyodbcTIME` class to avoid error thrown by `result_processor` in the (more) generic mysql/types.py. ### Checklist This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. **Have a nice day!** Closes: #4880 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4880 Pull-request-sha: 2e4c468c3ad685d6573e0d9755ba97a28df50b6c Change-Id: Ib5c5b0971969c2a9870b7f43d06703618cfc56f7 (cherry picked from commit f94940e4d88b4011fd089bed37cebb76acb1a385) --- diff --git a/lib/sqlalchemy/dialects/mysql/pyodbc.py b/lib/sqlalchemy/dialects/mysql/pyodbc.py index e8d2034a17..82d340fc09 100644 --- a/lib/sqlalchemy/dialects/mysql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mysql/pyodbc.py @@ -26,8 +26,19 @@ import re from .base import MySQLDialect from .base import MySQLExecutionContext +from .types import TIME from ... import util from ...connectors.pyodbc import PyODBCConnector +from ...sql.sqltypes import Time + + +class _pyodbcTIME(TIME): + def result_processor(self, dialect, coltype): + def process(value): + # pyodbc returns a datetime.time object; no need to convert + return value + + return process class MySQLExecutionContext_pyodbc(MySQLExecutionContext): @@ -40,6 +51,7 @@ class MySQLExecutionContext_pyodbc(MySQLExecutionContext): class MySQLDialect_pyodbc(PyODBCConnector, MySQLDialect): + colspecs = util.update_copy(MySQLDialect.colspecs, {Time: _pyodbcTIME}) supports_unicode_statements = False execution_ctx_cls = MySQLExecutionContext_pyodbc