From 28f181247ac475069eb8cd3669331e689fc78792 Mon Sep 17 00:00:00 2001 From: Paul Becotte Date: Sun, 23 Feb 2020 23:54:00 -0500 Subject: [PATCH] original comparison regex generates false positives in situations where parameters inside parentheses can mix with those outside of it. --- alembic/ddl/impl.py | 12 ++++++++---- tests/test_autogen_diffs.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py index 72fc2947..a62a3998 100644 --- a/alembic/ddl/impl.py +++ b/alembic/ddl/impl.py @@ -330,11 +330,15 @@ class DefaultImpl(with_metaclass(ImplMeta)): def _tokenize_column_type(self, column): definition = self.dialect.type_compiler.process(column.type).lower() - # py27 - py36 - col_type, *param_terms = re.findall... - matches = re.findall("[^(),]+", definition) - col_type, param_terms = matches[0], matches[1:] + matches = re.search( + r"^(?P[^()]*)(?:\((?P.*?)\))?(?P[^()]*)?$", + definition, + ).groupdict(default="") + col_type = matches["col"] + if matches["ext"]: + col_type = col_type.strip() + " " + matches["ext"].strip() params = Params(col_type, [], {}) - for term in param_terms: + for term in matches["params"].split(",") if matches["params"] else []: if "=" in term: key, val = term.split("=") params.kwargs[key.strip()] = val.strip() diff --git a/tests/test_autogen_diffs.py b/tests/test_autogen_diffs.py index 7a7702f7..52f148cd 100644 --- a/tests/test_autogen_diffs.py +++ b/tests/test_autogen_diffs.py @@ -31,6 +31,7 @@ from sqlalchemy import TypeDecorator from sqlalchemy import Unicode from sqlalchemy import UniqueConstraint from sqlalchemy import VARCHAR +from sqlalchemy.dialects import mysql from sqlalchemy.dialects import sqlite from sqlalchemy.types import NULLTYPE from sqlalchemy.types import VARBINARY @@ -842,6 +843,22 @@ class CompareMetadataToInspectorTest(TestBase): True, config.requirements.integer_subtype_comparisons, ), + ( + mysql.INTEGER(unsigned=True, display_width=10), + mysql.INTEGER(unsigned=True, display_width=10), + False, + ), + (mysql.INTEGER(unsigned=True), mysql.INTEGER(unsigned=True), False), + ( + mysql.INTEGER(unsigned=True, display_width=10), + mysql.INTEGER(unsigned=True), + False, + ), + ( + mysql.INTEGER(unsigned=True), + mysql.INTEGER(unsigned=True, display_width=10), + False, + ), ) def test_numeric_comparisons(self, cola, colb, expect_changes): is_(self._compare_columns(cola, colb), expect_changes) -- 2.47.2