Skip to content

Commit

Permalink
[FIX] Avoid use of context to pass the check_connection_method
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-dacosta authored and qgroulard committed Oct 7, 2024
1 parent 3c98a93 commit 7e1da09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
18 changes: 5 additions & 13 deletions fs_storage/models/fs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,13 @@ def _marker_file_check_connection(self, fs):
def _ls_check_connection(self, fs):
fs.ls("", detail=False)

def _check_connection_with_method(self, fs, check_connection_method):
def _check_connection(self, fs, check_connection_method):
if check_connection_method == "marker_file":
self._marker_file_check_connection(fs)
elif check_connection_method == "ls":
self._ls_check_connection(fs)
return True

def _check_connection(self, fs):
check_connection_method = self.check_connection_method or self.env.context.get(
"force_connection_method", ""
)
return self._check_connection_with_method(fs, check_connection_method)

@property
def fs(self) -> fsspec.AbstractFileSystem:
"""Get the fsspec filesystem for this backend."""
Expand All @@ -316,7 +310,7 @@ def fs(self) -> fsspec.AbstractFileSystem:
# Check whether we need to invalidate FS cache or not.
# Use a marker file to limit the scope of the LS command for performance.
try:
self._check_connection(self.__fs)
self._check_connection(self.__fs, self.check_connection_method)
except Exception as e:
self.__fs.clear_instance_cache()
self.__fs = None
Expand Down Expand Up @@ -484,19 +478,17 @@ def delete(self, relative_path) -> None:
def action_test_config(self):
self.ensure_one()
if self.check_connection_method:
return self._test_config()
return self._test_config(self.check_connection_method)
else:
action = self.env["ir.actions.actions"]._for_xml_id(
"fs_storage.act_open_fs_test_connection_view"
)
action["context"] = {"active_model": "fs.storage", "active_id": self.id}
return action

def _test_config(self):
def _test_config(self, connection_method):
try:
# Accessing the property will check the connection
# pylint: disable=W0104
self.fs
self._check_connection(self.fs, connection_method)
title = _("Connection Test Succeeded!")
message = _("Everything seems properly set up!")
msg_type = "success"
Expand Down
4 changes: 1 addition & 3 deletions fs_storage/wizards/fs_test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@ def default_get(self, field_list):
return res

def action_test_config(self):
return self.storage_id.with_context(
force_connection_method=self.check_connection_method
)._test_config()
return self.storage_id._test_config(self.check_connection_method)

0 comments on commit 7e1da09

Please sign in to comment.