summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-06-26 11:45:50 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-06-26 15:10:53 -0400
commit5cf8e14d58c89fdb94c60bf5e94d8b13d296da25 (patch)
tree9819e92b6dcce02ad453bac70841446843e0c05e /lib/sqlalchemy/dialects/postgresql/base.py
parent1ed2f1621510b48a6c46bedf3dd579c56bd89ccb (diff)
downloadsqlalchemy-5cf8e14d58c89fdb94c60bf5e94d8b13d296da25.tar.gz
Reflect "NO ACTION" as None; support "RESTRICT"
The "NO ACTION" keyword for foreign key "ON UPDATE" is now considered to be the default cascade for a foreign key on all supporting backends (SQlite, MySQL, PostgreSQL) and when detected is not included in the reflection dictionary; this is already the behavior for PostgreSQL and MySQL for all previous SQLAlchemy versions in any case. The "RESTRICT" keyword is positively stored when detected; PostgreSQL does report on this keyword, and MySQL as of version 8.0 does as well. On earlier MySQL versions, it is not reported by the database. Fixes: #4741 Change-Id: I6becf1f2450605c1991158bb8a04d954dcc7396c
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 2bc48c53e..5aea02cfc 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -3150,19 +3150,24 @@ class PGDialect(default.DefaultDialect):
preparer._unquote_identifier(x)
for x in re.split(r"\s*,\s", referred_columns)
]
+ options = {
+ k: v
+ for k, v in [
+ ("onupdate", onupdate),
+ ("ondelete", ondelete),
+ ("initially", initially),
+ ("deferrable", deferrable),
+ ("match", match),
+ ]
+ if v is not None and v != "NO ACTION"
+ }
fkey_d = {
"name": conname,
"constrained_columns": constrained_columns,
"referred_schema": referred_schema,
"referred_table": referred_table,
"referred_columns": referred_columns,
- "options": {
- "onupdate": onupdate,
- "ondelete": ondelete,
- "deferrable": deferrable,
- "initially": initially,
- "match": match,
- },
+ "options": options,
}
fkeys.append(fkey_d)
return fkeys