Repository navigation
Fix concurrent SFTP directory transfers dropping parent hook's connection overrides - #73647
Conversation
…ransfer workers SFTPHook.store_directory_concurrently() and retrieve_directory_concurrently() built each worker hook as SFTPHook(ssh_conn_id=self.ssh_conn_id), discarding every other constructor override on the parent hook (remote_host, port, username, password, key_file, proxy settings, timeouts, no_host_key_check, etc.). Workers fell back to the connection's raw defaults instead of the parent hook's effective, already-resolved settings. Add SFTPHook._build_worker_hook(), which builds a worker hook from the parent's effective connection settings, and use it in both store_directory_concurrently() and retrieve_directory_concurrently(). Closes apache#73585
rjgoyln
left a comment
There was a problem hiding this comment.
The overall approach looks good to me. I just have one potentially blocking concern below: re-passing the parent hook's already-resolved key_file to the worker constructor can cause _build_worker_hook() to raise in cases where the previous construction succeeded.
I also left two non-blocking comments on the tests — one on the assertions in the second regression test, and one on the mock spec.
Just my thoughts, and please feel free to resolve any of these if you think they're not applicable.
Drafted-by: Claude Code (Opus 5); reviewed by @rjgoyln before posting
- Re-resolve key_file when pkey is set on the worker hook, avoiding the key_file/private_key guard in SSHHook that could make worker construction raise even though the parent hook succeeded. - Use MagicMock(spec=Connection) in test_build_worker_hook_inherits_parent_overrides so the mock stays honest against the real Connection interface. - Simplify test_store_and_retrieve_directory_concurrently_use_parent_overrides to a wiring test (assert _build_worker_hook is called once per worker); value-level assertions are already covered by test_build_worker_hook_inherits_parent_overrides.
…verrides' into fix-sftp-concurrent-connection-overrides
|
Thanks for the review. Addressed all three points in 4fec830:
All 127 tests pass locally. |
potiuk
left a comment
There was a problem hiding this comment.
Approving. Worker hooks for concurrent transfers now get the parent hook's resolved settings (keys, host-key policy, proxy, username) instead of re-reading only the connection, so every transfer uses the same authentication and host verification as the parent. The regression tests cover both store and retrieve. Thanks!
Drafted-by: Claude Code (Opus 5.5); reviewed by @potiuk before posting
Closes #73585
What
SFTPHook.store_directory_concurrently()andretrieve_directory_concurrently()built each worker hook asSFTPHook(ssh_conn_id=self.ssh_conn_id), discarding every other constructor override on the parent hook —remote_host,port,username,password,key_file, proxy settings, timeouts, andno_host_key_check. Workers fell back to whatever the underlying connection defined instead of the parent hook's effective, already-resolved settings.With an explicit
remote_hostset on the parent hook, for example, the directory listing happened against that host but the worker transfers ran against the connection's original host.How
Added
SFTPHook._build_worker_hook(), a helper that constructs a newSFTPHookfrom the parent hook's effective connection settings (constructor overrides merged with the connection), and used it in bothstore_directory_concurrently()andretrieve_directory_concurrently()instead of re-constructing a bareSFTPHook(ssh_conn_id=...)per worker.Testing
Added two regression tests in
test_sftp.py:test_build_worker_hook_inherits_parent_overrides— unit-tests_build_worker_hook()directly, asserting it copiesremote_host,port,username,password,key_file,conn_timeout,host_proxy_cmd,no_host_key_check,allow_host_key_change, andlook_for_keys.test_store_and_retrieve_directory_concurrently_use_parent_overrides— patches_build_worker_hookand asserts every worker hook built during a concurrent store/retrieve transfer carries the parent's effectiveremote_host/port/username.Full
providers/sftpunit test suite passes locally (127 passed).