]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug in MySQL reflection where the "fractional sections portion"
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 7 Dec 2015 22:24:09 +0000 (17:24 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 7 Dec 2015 22:25:27 +0000 (17:25 -0500)
of the :class:`.mysql.DATETIME`, :class:`.mysql.TIMESTAMP` and
:class:`.mysql.TIME` types would be incorrectly placed into the
``timestamp`` attribute, which is unused by MySQL, instead of the
``fsp`` attribute.
fixes #3602

(cherry picked from commit 3f42743d6aa1326a80a0ed720a92266aa5fbf209)

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/dialects/mysql/base.py
test/dialect/mysql/test_reflection.py

index 6fc75b18b17cd13f2411263d3ec6e2c0e2ac84d8..3e7f6fd29b17a91ec2ff5afc41249f12cfdc14fe 100644 (file)
 .. changelog::
     :version: 1.0.10
 
+    .. change::
+        :tags: bug, mysql
+        :tickets: 3602
+        :versions: 1.1.0b1
+
+        Fixed bug in MySQL reflection where the "fractional sections portion"
+        of the :class:`.mysql.DATETIME`, :class:`.mysql.TIMESTAMP` and
+        :class:`.mysql.TIME` types would be incorrectly placed into the
+        ``timestamp`` attribute, which is unused by MySQL, instead of the
+        ``fsp`` attribute.
+
     .. change::
         :tags: bug, orm
         :tickets: 3599
index 9cd804e43906bda24da63a9b8b7a4747194e8ad9..6626b39387aedc40b95b5d3656f07b20b91bb0f7 100644 (file)
@@ -3122,6 +3122,11 @@ class MySQLTableDefinitionParser(object):
 
         # Column type keyword options
         type_kw = {}
+
+        if issubclass(col_type, (DATETIME, TIME, TIMESTAMP)):
+            if type_args:
+                type_kw['fsp'] = type_args.pop(0)
+
         for kw in ('unsigned', 'zerofill'):
             if spec.get(kw, False):
                 type_kw[kw] = True
index 2b8010c70ef2ad5ee6d0c6ee1fc86a85e32120a7..ff5b3e681f4dcdee5de23d3b3f35003c65843bc0 100644 (file)
@@ -72,8 +72,14 @@ class TypeReflectionTest(fixtures.TestBase):
         specs = []
 
         for type_ in (mysql.TIMESTAMP, mysql.DATETIME, mysql.TIME):
-            typespec = type_()
-            specs.append((typespec, typespec))
+            # MySQL defaults fsp to 0, and if 0 does not report it.
+            # we don't actually render 0 right now in DDL but even if we do,
+            # it comes back blank
+            for fsp in (None, 0, 5):
+                if fsp:
+                    specs.append((type_(fsp=fsp), type_(fsp=fsp)))
+                else:
+                    specs.append((type_(), type_()))
 
         specs.extend([
             (TIMESTAMP(), mysql.TIMESTAMP()),