diff options
-rw-r--r-- | doc/build/changelog/unreleased_13/5744.rst | 10 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/reflection.py | 4 | ||||
-rw-r--r-- | test/dialect/mysql/test_reflection.py | 19 |
3 files changed, 31 insertions, 2 deletions
diff --git a/doc/build/changelog/unreleased_13/5744.rst b/doc/build/changelog/unreleased_13/5744.rst new file mode 100644 index 000000000..7325279e8 --- /dev/null +++ b/doc/build/changelog/unreleased_13/5744.rst @@ -0,0 +1,10 @@ +.. change:: + :tags: bug, mysql, reflection + :tickets: 5744 + :versions: 1.4.0b2 + + Fixed issue where reflecting a server default on MariaDB only that + contained a decimal point in the value would fail to be reflected + correctly, leading towards a reflected table that lacked any server + default. + diff --git a/lib/sqlalchemy/dialects/mysql/reflection.py b/lib/sqlalchemy/dialects/mysql/reflection.py index 5be6a010e..14fb97c64 100644 --- a/lib/sqlalchemy/dialects/mysql/reflection.py +++ b/lib/sqlalchemy/dialects/mysql/reflection.py @@ -381,8 +381,8 @@ class MySQLTableDefinitionParser(object): r"(?: +COLLATE +(?P<collate>[\w_]+))?" r"(?: +(?P<notnull>(?:NOT )?NULL))?" r"(?: +DEFAULT +(?P<default>" - r"(?:NULL|'(?:''|[^'])*'|[\w\(\)]+" - r"(?: +ON UPDATE [\w\(\)]+)?)" + r"(?:NULL|'(?:''|[^'])*'|[\w\.\(\)]+" + r"(?: +ON UPDATE [\w\.\(\)]+)?)" r"))?" r"(?: +(?:GENERATED ALWAYS)? ?AS +(?P<generated>\(" r".*\))? ?(?P<persistence>VIRTUAL|STORED)?)?" diff --git a/test/dialect/mysql/test_reflection.py b/test/dialect/mysql/test_reflection.py index d5684b22f..3871dbecc 100644 --- a/test/dialect/mysql/test_reflection.py +++ b/test/dialect/mysql/test_reflection.py @@ -234,6 +234,9 @@ class ReflectionTest(fixtures.TestBase, AssertsCompiledSQL): def test_default_reflection(self): """Test reflection of column defaults.""" + # TODO: this test is a mess. should be broken into individual + # combinations + from sqlalchemy.dialects.mysql import VARCHAR def_table = Table( @@ -258,6 +261,8 @@ class ReflectionTest(fixtures.TestBase, AssertsCompiledSQL): ) ), ), + Column("c7", mysql.DOUBLE(), DefaultClause("0.0000")), + Column("c8", mysql.DOUBLE(22, 6), DefaultClause("0.0000")), ) def_table.create(testing.db) @@ -280,6 +285,15 @@ class ReflectionTest(fixtures.TestBase, AssertsCompiledSQL): assert reflected.c.c5.default is None assert reflected.c.c5.server_default is None assert reflected.c.c6.default is None + assert str(reflected.c.c7.server_default.arg) in ("0", "'0'") + + # this is because the numeric is 6 decimal places, MySQL + # formats it to that many places. + assert str(reflected.c.c8.server_default.arg) in ( + "0.000000", + "'0.000000'", + ) + assert re.match( r"CURRENT_TIMESTAMP(\(\))? ON UPDATE CURRENT_TIMESTAMP(\(\))?", str(reflected.c.c6.server_default.arg).upper(), @@ -300,6 +314,11 @@ class ReflectionTest(fixtures.TestBase, AssertsCompiledSQL): assert reflected.c.c5.default is None assert reflected.c.c5.server_default is None assert reflected.c.c6.default is None + assert str(reflected.c.c7.server_default.arg) in ("0", "'0'") + assert str(reflected.c.c8.server_default.arg) in ( + "0.000000", + "'0.000000'", + ) assert re.match( r"CURRENT_TIMESTAMP(\(\))? ON UPDATE CURRENT_TIMESTAMP(\(\))?", str(reflected.c.c6.server_default.arg).upper(), |