From 735fbfdf4907ba7888b8408bceaf8ffb99602720 Mon Sep 17 00:00:00 2001 From: Jacob Hayes Date: Mon, 8 May 2017 16:26:06 -0400 Subject: [PATCH] Support autocommit for GRANT and REVOKE on postgresql Extends `AUTOCOMMIT_REGEXP` for the postgres dialect to include `GRANT` and `REVOKE`. Change-Id: Iba15f1ebf5bd7bc0fc1193fdf561417e53bf5d57 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/357 --- doc/build/changelog/changelog_11.rst | 7 +++++++ lib/sqlalchemy/dialects/postgresql/base.py | 2 +- test/dialect/postgresql/test_dialect.py | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 2a44a2f100..f284b5b00b 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -32,6 +32,13 @@ infrequently hitting a weakref that has not been fully acted upon after gc. + .. change:: + :tags: bug, postgresql + :versions: 1.2.0b1 + + Added "autocommit" support for GRANT, REVOKE keywords. Pull request + courtesy Jacob Hayes. + .. change:: 3966 :tags: bug, mysql :versions: 1.2.0b1 diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index b9c15ca2db..2510bc9752 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -890,7 +890,7 @@ from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, VARCHAR, \ DATE, BOOLEAN, REAL AUTOCOMMIT_REGEXP = re.compile( - r'\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER|' + r'\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER|GRANT|REVOKE|' 'IMPORT FOREIGN SCHEMA|REFRESH MATERIALIZED VIEW)', re.I | re.UNICODE) diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py index f03b48790d..c79b186de0 100644 --- a/test/dialect/postgresql/test_dialect.py +++ b/test/dialect/postgresql/test_dialect.py @@ -304,8 +304,14 @@ class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): class AutocommitTextTest(test_execute.AutocommitTextTest): __only_on__ = 'postgresql' + def test_grant(self): + self._test_keyword("GRANT USAGE ON SCHEMA fooschema TO foorole") + def test_import_foreign_schema(self): self._test_keyword("IMPORT FOREIGN SCHEMA foob") def test_refresh_view(self): self._test_keyword("REFRESH MATERIALIZED VIEW fooview") + + def test_revoke(self): + self._test_keyword("REVOKE USAGE ON SCHEMA fooschema FROM foorole") -- 2.39.5