Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

un-indenting head-safe check to apply for cached files too #3232

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

eas342
Copy link

@eas342 eas342 commented Feb 27, 2025

Un-indenting the head-safe boolean check to apply to both fixing incomplete cached files and new files. This appears to fix this issue:
#3231

However, I do not understand what this head_safe keyword does, so please check that this does not break the intended functionality or flow.

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 84.21053% with 3 lines in your changes missing coverage. Please review.

Project coverage is 69.32%. Comparing base (1f45a44) to head (b599c09).
Report is 87 commits behind head on main.

Files with missing lines Patch % Lines
astroquery/query.py 84.21% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3232      +/-   ##
==========================================
+ Coverage   69.08%   69.32%   +0.23%     
==========================================
  Files         232      232              
  Lines       19592    19661      +69     
==========================================
+ Hits        13536    13630      +94     
+ Misses       6056     6031      -25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@snbianco
Copy link
Contributor

snbianco commented Mar 4, 2025

Hi again @eas342, thanks for this PR! This change is to a file in the main Astroquery directory and not part of any particular module, so it will impact more than just the MAST module. I would rather we change the MAST module directly so that it knows to continue incomplete file downloads. See my comment on the issue here: #3231 (comment)

Copy link
Contributor

@snbianco snbianco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment!

Copy link
Contributor

@keflavich keflavich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unindenting this block is not the correct behavior; it will overwrite the continuation block above, which would result in the download continuation failing - it will download the whole file and append it to whatever was partly completed.

However, this same code block (the if head_safe: response = request(...) block) needs to be repeated above, in the other location open_mode='wb'

@eas342
Copy link
Author

eas342 commented Mar 17, 2025

Thank you @keflavich ,

Unfortunately, the change you made does not seem to pass #3231

import os
from astropy.io import fits
from astroquery.mast import Observations
fileN = 'jw01185103001_02102_00001-seg001_nrcalong_rate.fits'
#os.remove(fileN)
Observations.download_file('mast:jwst/product/' + fileN)
with open(fileN, 'r+') as f:
    f.seek(1000)
    f.truncate()
Observations.download_file('mast:jwst/product/' + fileN)
tmpHDU = fits.open(fileN)

WARNING: Found cached file jw01185103001_02102_00001-seg001_nrcalong_rate.fits with size 0 that is different from expected size 83520 [astroquery.query]
Downloading URL https://mast.stsci.edu/api/v0.1/Download/file?uri=mast:jwst/product/jw01185103001_02102_00001-seg001_nrcalong_rate.fits to jw01185103001_02102_00001-seg001_nrcalong_rate.fits ...
|==========================================| 83k/ 83k (100.00%) 0s
WARNING: Found cached file jw01185103001_02102_00001-seg001_nrcalong_rate.fits with size 1000 that is different from expected size 83520 [astroquery.query]
Downloading URL https://mast.stsci.edu/api/v0.1/Download/file?uri=mast:jwst/product/jw01185103001_02102_00001-seg001_nrcalong_rate.fits to jw01185103001_02102_00001-seg001_nrcalong_rate.fits ...
|==========================================| 83k/ 83k (100.00%) 0s
OSError: Empty or corrupt FITS file

continuation was set to False (which is the case - MAST hard-codes
that), no download was being done - we were only retrieving the header,
not the data
@keflavich
Copy link
Contributor

Thanks @eas342. Indeed, there was another corner case we hadn't checked. The latest commit catches it.

@bsipocz bsipocz added this to the v0.4.11 milestone Mar 17, 2025
@eas342
Copy link
Author

eas342 commented Mar 17, 2025

That works, super! Thank you @keflavich

@bsipocz
Copy link
Member

bsipocz commented Mar 17, 2025

@eas342 @keflavich - I'm not sure how to test this in CI, etc. But if you are certain it covers all the cases, and add a changelog, it can still go in the next release ~tomorrow.
But if there is no rush or there is any uncertainty, then it should sit the release out and get it merged after it's out to have it in main for a little longer.

@keflavich
Copy link
Contributor

let's add tests; i think i can turn @eas342 's mwe into a test easily enough. so delay merging

@keflavich keflavich requested a review from bsipocz March 18, 2025 15:10
@keflavich
Copy link
Contributor

@bsipocz this is ready for final review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants