From: Denis Laxalde Date: Thu, 13 Mar 2025 07:13:49 +0000 (+0100) Subject: Move FK_ON_DELETE as a memoized property on PGDDLCompiler X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=848f1275c74d5e69382c73d81a5daa7e25e36d8e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Move FK_ON_DELETE as a memoized property on PGDDLCompiler --- diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index ccc426b5bf..4938aba2bd 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1672,10 +1672,6 @@ RESERVED_WORDS = { "verbose", } -FK_ON_DELETE = re.compile( - r"^(?:RESTRICT|CASCADE|SET (?:NULL|DEFAULT)(?:\s*\(.+\))?|NO ACTION)$", - re.I, -) colspecs = { sqltypes.ARRAY: _array.ARRAY, @@ -2255,9 +2251,17 @@ class PGDDLCompiler(compiler.DDLCompiler): text += self._define_constraint_validity(constraint) return text + @util.memoized_property + def _fk_ondelete_pattern(self): + return re.compile( + r"^(?:RESTRICT|CASCADE|SET (?:NULL|DEFAULT)(?:\s*\(.+\))?" + r"|NO ACTION)$", + re.I, + ) + def define_constraint_ondelete_cascade(self, constraint): return " ON DELETE %s" % self.preparer.validate_sql_phrase( - constraint.ondelete, FK_ON_DELETE + constraint.ondelete, self._fk_ondelete_pattern ) def visit_create_enum_type(self, create, **kw):