Add and use _remove_invalid_keyword_argument
This commit is contained in:
1 parent
41215b9148
commit
3fe7203ed5
1 file changed
+20
-8
@@ -26,6 +26,24 @@ class DatabaseWrapper(base.DatabaseWrapper):
|
|||||||
cursor.execute(init_cmd.strip())
|
cursor.execute(init_cmd.strip())
|
||||||
|
|
||||||
|
|
||||||
|
def _remove_invalid_keyword_argument(self, e, filtered_params):
|
||||||
|
key = None
|
||||||
|
try:
|
||||||
|
prog = re.compile(r"^'(?P<key>[^']+)' is an invalid keyword argument for Connection[()]{2}$")
|
||||||
|
match = prog.match(e.args[0])
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
if match:
|
||||||
|
key = match.group('key')
|
||||||
|
finally:
|
||||||
|
# This isn't a TypeError we can handle
|
||||||
|
if key is None:
|
||||||
|
raise e
|
||||||
|
# remove the invalid keyword argument
|
||||||
|
del filtered_params[key]
|
||||||
|
|
||||||
|
|
||||||
def get_new_connection(self, conn_params):
|
def get_new_connection(self, conn_params):
|
||||||
filter_map = {
|
filter_map = {
|
||||||
"transaction_mode": ("isolation_level", "DEFERRED"),
|
"transaction_mode": ("isolation_level", "DEFERRED"),
|
||||||
@@ -37,16 +55,10 @@ class DatabaseWrapper(base.DatabaseWrapper):
|
|||||||
connection = None
|
connection = None
|
||||||
tries = len(filtered_params)
|
tries = len(filtered_params)
|
||||||
while connection is None and attempt < tries:
|
while connection is None and attempt < tries:
|
||||||
|
attempt += 1
|
||||||
try:
|
try:
|
||||||
attempt += 1
|
|
||||||
connection = super().get_new_connection(filtered_params)
|
connection = super().get_new_connection(filtered_params)
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
prog = re.compile("^'(?P<key>[^']+)' is an invalid keyword argument for Connection[()]{2}$")
|
self._remove_invalid_keyword_argument(e, filtered_params)
|
||||||
match = prog.match(e.args[0])
|
|
||||||
key = match.group('key') if match else None
|
|
||||||
if key is None:
|
|
||||||
raise e
|
|
||||||
del filtered_params[key]
|
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user