Conversation
Both commands called the async FTP client without awaiting it, used a
`Dataset.get_files()` method that does not exist, never connected, and
never wrote the files:
ftp = _get_ftp()
try:
datasets = ftp.datasets() # coroutine, never awaited
...
remote_files = target.get_files() # AttributeError
...
ftp.download(f, out_dir) # coroutine, never awaited
finally:
ftp.close() # coroutine, never awaited
`connect`, `datasets`, `download` and `close` are all `async def`, and
datasets expose their files through the `content`/`search` contract
rather than `get_files()`. `pysus ftp files SINAN` died with
"TypeError: 'coroutine' object is not iterable", and `pysus ftp download`
printed "Downloading N file(s)..." and "Done. Files saved to ..." with
exit code 0 while transferring nothing.
The two commands now run inside an async helper driven by `_run_sync`,
the same bridge the dadosgov CLI uses, so they also work under Jupyter.
The FTP session is opened with `connect()` and closed in `finally`, and
the dataset is located by class name. `get_files()` is replaced with
`search()`, which recurses through groups to the files. Filters compare
against `str(f.path)` so a non-str path cannot raise, and `download` now
awaits each transfer and writes `out_dir / <basename>` instead of
handing the whole remote path to `open()`.
The duplicated filter block moved into a shared `_select_files`, and
dataset lookup into `_resolve_dataset`.
devgtv
force-pushed
the
fix/cli-ftp-await-and-list-files
branch
from
October 2, 2026 19:18
df49e9c to
bdbba0b
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #354 +/- ##
=======================================
Coverage ? 97.21%
=======================================
Files ? 180
Lines ? 23371
Branches ? 0
=======================================
Hits ? 22721
Misses ? 650
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Both commands called the async FTP client without awaiting it, used a method that doesn't exist, never connected, and never wrote any file:
connect,datasets,downloadandcloseare allasync definpysus/api/ftp/client.py. Datasets expose their files through thecontent/searchcontract (BaseRemoteDataset), notget_files()— which appears nowhere else in the codebase.connect()was also never called, anddatasets()itself raisesConnectionErrorwhen the client is not connected.Impact
pysus ftp files SINAN→TypeError: 'coroutine' object is not iterablepysus ftp download SINAN→ printedDownloading 3 file(s)...andDone. Files saved to ...with exit code 0, having written zero bytesTwo of the command's four behaviors were entirely non-functional, and the download path reported false success.
Fix
asynchelper driven by_run_sync, the same bridge the dadosgov CLI uses (so they also work under Jupyter, whereasyncio.runwould fail)await ftp.connect()opens the session;await ftp.close()runs infinallyget_files()→await target.search(), which recurses through groups to the filesstr(f.path)so a non-str path cannot raisedownloadawaits each transfer and writesout_dir / <basename>rather than handing the full remote path toopen()_select_files, and the class-name lookup into_resolve_datasetTests
The existing
test_ftp.pyonly covered the bad-slug path, so nothing ever reached these lines. Added 7 tests with a fake async client covering: listing files, the--yearfilter, no-match exiting 0,close()on error, all 3 transfers being awaited, writing basenames rather than full remote paths, and no false "Done." on no-match.Verified all 7 fail against the previous code (
TypeError: 'coroutine' object is not iterablepluscoroutine ... was never awaitedwarnings).1740 passed, 6 skippedblackandisortclean