From: Matt del Valle Date: Mon, 13 Mar 2023 18:38:31 +0000 (-0400) Subject: Add override hook PGDialect.set_backslash_escapes() X-Git-Tag: rel_2_0_7~5^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=65eb057d0c586f2eed43ac0731822053f0f6d472;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add override hook PGDialect.set_backslash_escapes() ### Description Refactor out the lines in `PGDialect.initialize()` that set backslash escapes into their own method to provide an override hook for [`sqlalchemy-redshift`](https://github.com/sqlalchemy-redshift/sqlalchemy-redshift) to use. Fixes #9442 ### 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. Closes: #9475 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9475 Pull-request-sha: 5565afeac20ea3612c3f427f58efacd8487ac159 Change-Id: I9b652044243ab231c19ab55ebc8ee24534365d61 --- diff --git a/doc/build/changelog/unreleased_20/9442.rst b/doc/build/changelog/unreleased_20/9442.rst new file mode 100644 index 0000000000..2b172195c6 --- /dev/null +++ b/doc/build/changelog/unreleased_20/9442.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: usecase, postgresql + :tickets: 9442 + + Modifications to the base PostgreSQL dialect to allow for better integration with the + sqlalchemy-redshift third party dialect for SQLAlchemy 2.0. Pull request courtesy + matthewgdv. diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 3ba1038026..3c1fc00734 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -3030,10 +3030,7 @@ class PGDialect(default.DefaultDialect): # https://www.postgresql.org/docs/9.3/static/release-9-2.html#AEN116689 self.supports_smallserial = self.server_version_info >= (9, 2) - std_string = connection.exec_driver_sql( - "show standard_conforming_strings" - ).scalar() - self._backslash_escapes = std_string == "off" + self._set_backslash_escapes(connection) self._supports_drop_index_concurrently = self.server_version_info >= ( 9, @@ -4699,3 +4696,11 @@ class PGDialect(default.DefaultDialect): domains.append(domain_rec) return domains + + def _set_backslash_escapes(self, connection): + # this method is provided as an override hook for descendant + # dialects (e.g. Redshift), so removing it may break them + std_string = connection.exec_driver_sql( + "show standard_conforming_strings" + ).scalar() + self._backslash_escapes = std_string == "off"