From: roche-quentin Date: Wed, 8 May 2024 10:48:09 +0000 (-0400) Subject: Add ``SET DEFAULT`` reflection option X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=323a7dcb5e70ae555e771beb63e3a58158f003a2;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add ``SET DEFAULT`` reflection option Added missing foreign key reflection option ``SET DEFAULT`` in the MySQL and MariaDB dialects. Fixes: #11285 Closes: #11368 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11368 Pull-request-sha: dbd9c239c60b8f4f2be66967825ee15c1f7941b0 Change-Id: If61d3365fc4271432d5591d1b50e10f4a1da9290 --- diff --git a/doc/build/changelog/unreleased_20/11285.rst b/doc/build/changelog/unreleased_20/11285.rst new file mode 100644 index 0000000000..a965799c17 --- /dev/null +++ b/doc/build/changelog/unreleased_20/11285.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: usecase, reflection, mysql + :tickets: 11285 + + Added missing foreign key reflection option ``SET DEFAULT`` + in the MySQL and MariaDB dialects. + Pull request courtesy of Quentin Roche. diff --git a/lib/sqlalchemy/dialects/mysql/reflection.py b/lib/sqlalchemy/dialects/mysql/reflection.py index c764e8ccc7..d7622c5463 100644 --- a/lib/sqlalchemy/dialects/mysql/reflection.py +++ b/lib/sqlalchemy/dialects/mysql/reflection.py @@ -505,7 +505,7 @@ class MySQLTableDefinitionParser: # # unique constraints come back as KEYs kw = quotes.copy() - kw["on"] = "RESTRICT|CASCADE|SET NULL|NO ACTION" + kw["on"] = "RESTRICT|CASCADE|SET NULL|NO ACTION|SET DEFAULT" self._re_fk_constraint = _re_compile( r" " r"CONSTRAINT +" diff --git a/test/dialect/mysql/test_reflection.py b/test/dialect/mysql/test_reflection.py index 79e7198ef3..4fa472ce1a 100644 --- a/test/dialect/mysql/test_reflection.py +++ b/test/dialect/mysql/test_reflection.py @@ -1557,7 +1557,7 @@ class RawReflectionTest(fixtures.TestBase): " CONSTRAINT `addresses_user_id_fkey` " "FOREIGN KEY (`user_id`) " "REFERENCES `users` (`id`) " - "ON DELETE CASCADE ON UPDATE SET NULL" + "ON DELETE SET DEFAULT ON UPDATE SET NULL" ) eq_( m.groups(), @@ -1567,7 +1567,7 @@ class RawReflectionTest(fixtures.TestBase): "`users`", "`id`", None, - "CASCADE", + "SET DEFAULT", "SET NULL", ), )