Pass the exception argument

Fixed up the try syntax too.
I really dislike try, but it's almost mandatory in Python.
This commit is contained in:
tcely authored and GitHub committed 2024-12-12 13:59:06 -05:00
1 parent ba0d5ab285
commit 11789df864
1 file changed
+16 -9
+16 -9
View File
@@ -26,18 +26,23 @@ class DatabaseWrapper(base.DatabaseWrapper):
cursor.execute(init_cmd.strip()) cursor.execute(init_cmd.strip())
def _remove_invalid_keyword_argument(self, params): def _remove_invalid_keyword_argument(self, arg_str, params):
try: try:
prog = re.compile(r"^(?P<quote>['])(?P<key>[^']+)(?P=quote) is an invalid keyword argument for Connection\(\)$") prog = re.compile(r"^(?P<quote>['])(?P<key>[^']+)(?P=quote) is an invalid keyword argument for Connection\(\)$")
match = prog.match(e.args[0]) match = prog.match(arg_str)
if match is None:
if match: return False
key = match.group('key') key = match.group('key')
try:
# remove the invalid keyword argument
del params[key]
return True
# remove the invalid keyword argument
del params[key]
return True
except:
raise
# It's unlikely that this will ever be reached, however,
# it was left here intentionally, so don't remove it.
return False return False
@@ -56,8 +61,10 @@ class DatabaseWrapper(base.DatabaseWrapper):
try: try:
connection = super().get_new_connection(filtered_params) connection = super().get_new_connection(filtered_params)
except TypeError as e: except TypeError as e:
if not self._remove_invalid_keyword_argument(filtered_params): e_arg = str(e.args[0])
if not self._remove_invalid_keyword_argument(e_arg, filtered_params):
# This isn't a TypeError we can handle # This isn't a TypeError we can handle
raise e raise e
return connection return connection