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.
This commit is contained in:
tcely 2024-12-12 09:52:51 -05:00 committed by GitHub
parent 21e9cbef4b
commit 7b033d6e62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)