From: krzysdz Date: Thu, 29 Jun 2023 22:00:55 +0000 (-0400) Subject: Allow reflecting UUID in MariaDB X-Git-Tag: rel_2_0_18~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=044f367dcb8eb2eacd8e380231baa66e8e560f10;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Allow reflecting UUID in MariaDB ### Description 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 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: #10029 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10029 Pull-request-sha: 7c2838b1dd5a34166158f5e241af72a6d3d8be85 Change-Id: Ifa1f51f472809b35374a7e2c6b85412046133452 --- diff --git a/doc/build/changelog/unreleased_20/10028.rst b/doc/build/changelog/unreleased_20/10028.rst new file mode 100644 index 0000000000..6c075abaae --- /dev/null +++ b/doc/build/changelog/unreleased_20/10028.rst @@ -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. diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 18e64f1b48..9bfd2be25a 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -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, diff --git a/test/dialect/mysql/test_reflection.py b/test/dialect/mysql/test_reflection.py index e5e35c9504..f3d1f34599 100644 --- a/test/dialect/mysql/test_reflection.py +++ b/test/dialect/mysql/test_reflection.py @@ -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"