Automated invalid keyword argument removal
Less manual maintenance as versions change is a win!
This commit is contained in:
1 parent
32dead2126
commit
41215b9148
1 file changed
+8
-6
@@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
from django.db.backends.sqlite3 import base
|
from django.db.backends.sqlite3 import base
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ class DatabaseWrapper(base.DatabaseWrapper):
|
|||||||
"transaction_mode": ("isolation_level", "DEFERRED"),
|
"transaction_mode": ("isolation_level", "DEFERRED"),
|
||||||
}
|
}
|
||||||
filtered_params = {k: v for (k,v) in conn_params.items() if k not in filter_map}
|
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})
|
filtered_params.update({v[0]: conn_params.get(k, v[1]) for (k,v) in filter_map.items()})
|
||||||
|
|
||||||
attempt = 0
|
attempt = 0
|
||||||
connection = None
|
connection = None
|
||||||
@@ -40,11 +41,12 @@ class DatabaseWrapper(base.DatabaseWrapper):
|
|||||||
attempt += 1
|
attempt += 1
|
||||||
connection = super().get_new_connection(filtered_params)
|
connection = super().get_new_connection(filtered_params)
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
# remove unaccepted param
|
prog = re.compile("^'(?P<key>[^']+)' is an invalid keyword argument for Connection[()]{2}$")
|
||||||
print(e, flush=True)
|
match = prog.match(e.args[0])
|
||||||
print('Exception args:', flush=True)
|
key = match.group('key') if match else None
|
||||||
print(e.args, flush=True)
|
if key is None:
|
||||||
del filtered_params["init_command"]
|
raise e
|
||||||
|
del filtered_params[key]
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user