]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Allow reflecting UUID in MariaDB
authorkrzysdz <krzysdz@users.noreply.github.com>
Thu, 29 Jun 2023 22:00:55 +0000 (18:00 -0400)
committersqla-tester <sqla-tester@sqlalchemy.org>
Thu, 29 Jun 2023 22:00:55 +0000 (18:00 -0400)
<!-- Provide a general summary of your proposed changes in the Title field above -->

### Description
<!-- Describe your changes in detail -->

Added the `"uuid"` key to `ischema_names` to enable lookup of `UUID` columns in reflection. There's also a new short test (MariaDB 10.7+ only) in the mysql reflection tests to verify if this feature works correctly.

Fixes #10028

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

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: #<issue number>` 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: #<issue number>` in the commit message
- please include tests.

**Have a nice day!**

Closes: #10029
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10029
Pull-request-sha: 7c2838b1dd5a34166158f5e241af72a6d3d8be85

Change-Id: Ifa1f51f472809b35374a7e2c6b85412046133452

doc/build/changelog/unreleased_20/10028.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/base.py
test/dialect/mysql/test_reflection.py

diff --git a/doc/build/changelog/unreleased_20/10028.rst b/doc/build/changelog/unreleased_20/10028.rst
new file mode 100644 (file)
index 0000000..6c075ab
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+       :tags: usecase, mariadb, reflection
+       :tickets: 10028
+
+       Allowed reflecting :class:`_types.UUID` columns from MariaDB. This allows
+       Alembic to properly detect the type of such columns in existing MariaDB
+       databases.
index 18e64f1b484655120268a4fddaeaeb4db733bc34..9bfd2be25a13f128d134cd52cc7e4ee252624e12 100644 (file)
@@ -1067,6 +1067,7 @@ from ...types import BINARY
 from ...types import BLOB
 from ...types import BOOLEAN
 from ...types import DATE
+from ...types import UUID
 from ...types import VARBINARY
 from ...util import topological
 
@@ -1155,6 +1156,7 @@ ischema_names = {
     "tinyblob": TINYBLOB,
     "tinyint": TINYINT,
     "tinytext": TINYTEXT,
+    "uuid": UUID,
     "varbinary": VARBINARY,
     "varchar": VARCHAR,
     "year": YEAR,
index e5e35c9504a11389b69fee9f79ca9910c42935d1..f3d1f34599b00c3a5ed68afaf41af824787f04f7 100644 (file)
@@ -242,6 +242,13 @@ class TypeReflectionTest(fixtures.TestBase):
 
         self._run_test(metadata, connection, specs, ["enums"])
 
+    @testing.only_on("mariadb>=10.7")
+    def test_uuid(self, metadata, connection):
+        specs = [
+            (mysql.UUID(), mysql.UUID()),
+        ]
+        self._run_test(metadata, connection, specs, [])
+
 
 class ReflectionTest(fixtures.TestBase, AssertsCompiledSQL):
     __only_on__ = "mysql", "mariadb"