From 7b033d6e620c5320c35ee6cff14c851922fc769e Mon Sep 17 00:00:00 2001 From: tcely Date: Thu, 12 Dec 2024 09:52:51 -0500 Subject: [PATCH] Use a filter map to make maintenance easier A possible future improvement would be to define a map of which keys Connection accepts. Right now, this is removing keys after Connection fails because of an unknown key. This could be automated by using try and removing a key each time the exception is caught. --- tubesync/tubesync/sqlite3/base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tubesync/tubesync/sqlite3/base.py b/tubesync/tubesync/sqlite3/base.py index 28d0ebc7..b2d10a20 100644 --- a/tubesync/tubesync/sqlite3/base.py +++ b/tubesync/tubesync/sqlite3/base.py @@ -26,9 +26,12 @@ class DatabaseWrapper(base.DatabaseWrapper): def get_new_connection(self, conn_params): - filtered_params = conn_params.copy() - filtered_params["isolation_level"] = filtered_params.pop("transaction_mode", "DEFERRED") - _ = filtered_params.pop("init_command", None) + filter_map = { + "init_command": None, + "transaction_mode": ("isolation_level", "DEFERRED"), + } + filtered_params = {k: v for (k,v) in conn_params.items() if k not in filter_map} + filtered_params.update({v[0]: conn_params.get(k, v[1]) for (k,v) in filter_map.items() if v is not None}) return super().get_new_connection(filtered_params)