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

fix: Avoid raising 404 when file cannot generate a thumbnail #642

Merged
merged 27 commits into from Dec 8, 2021

Conversation

DaveSawyer
Copy link
Contributor

@DaveSawyer DaveSawyer commented Dec 4, 2021

for issue #641. For some files that cannot generate thumbnails we should not attempt to download from the url field. If we do, an application may interpret the 404 not found as similar to "try again in case the thumbnail was in the process of being generated." We can also avoid an extra network call that we know will fail.

I made this intentionally narrow (as opposed to status != 'success') because some failures might be solved by waiting and retrying or actually have a valid URL.

@DaveSawyer DaveSawyer changed the title Avoid raising 404 when file cannot generate a thumbnail Fix raising 404 when file cannot generate a thumbnail Dec 4, 2021
@DaveSawyer DaveSawyer changed the title Fix raising 404 when file cannot generate a thumbnail Fix: raising 404 when file cannot generate a thumbnail Dec 4, 2021
@DaveSawyer DaveSawyer changed the title Fix: raising 404 when file cannot generate a thumbnail fix: raising 404 when file cannot generate a thumbnail Dec 4, 2021
@DaveSawyer DaveSawyer changed the title fix: raising 404 when file cannot generate a thumbnail fix: avoid raising 404 when file cannot generate a thumbnail Dec 4, 2021
@coveralls
Copy link

coveralls commented Dec 4, 2021

Pull Request Test Coverage Report for Build 2739

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 96.751%

Totals Coverage Status
Change from base Build 2733: 0.003%
Covered Lines: 3186
Relevant Lines: 3293

💛 - Coveralls

@DaveSawyer DaveSawyer changed the title fix: avoid raising 404 when file cannot generate a thumbnail fix: Avoid raising 404 when file cannot generate a thumbnail Dec 4, 2021
@antusus
Copy link
Contributor

antusus commented Dec 6, 2021

Hi @DaveSawyer ,

Thanks for this contribution! We will review it ASAP!

@antusus

if representation:
url = representation[0]['content']['url_template']
representations = self.get_representation_info(rep_hints)
if len(representations):
Copy link
Contributor

Choose a reason for hiding this comment

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

An empty list is treated as False, so if representations: is enough

Copy link
Contributor

@antusus antusus left a comment

Choose a reason for hiding this comment

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

Looks OK. I have some questions.

boxsdk/object/file.py Show resolved Hide resolved
@antusus
Copy link
Contributor

antusus commented Dec 7, 2021

Please wait with merging until we solve the travis build issue.

Copy link
Contributor

@antusus antusus left a comment

Choose a reason for hiding this comment

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

One thing that I overlooked - could you ad an entry to HISTORY.srt

@lukaszsocha2
Copy link
Contributor

Also pylint is failing with messages:
`test.unit.object.test_file:904:11: [C0122(misplaced-comparison-constant), test_get_thumbnail_representation_not_found] Comparison should be thumb == ''

test.unit.object.test_file:950:11: [C0122(misplaced-comparison-constant), test_get_thumbnail_representation_not_available] Comparison should be thumb == ''`

@@ -901,4 +901,50 @@ def test_get_thumbnail_representation_not_found(
headers={'X-Rep-Hints': '[{}?dimensions={}]'.format(extension, dimensions)},
params={'fields': 'representations'},
)
assert thumb == b''
assert b'' == thumb
Copy link
Contributor

Choose a reason for hiding this comment

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

assert thumb == b''

Copy link
Contributor Author

@DaveSawyer DaveSawyer Dec 7, 2021

Choose a reason for hiding this comment

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

They are equivalent and in general it's better to put a constant on the left so you don't accidentally have an assignment from a typo. This is the existing code.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see your point, but according to pylint the other way around it preferred, see: https://vald-phoenix.github.io/pylint-errors/plerr/errors/basic/C0122 . Without fixing it the build will be still failing.

headers={'X-Rep-Hints': '[{}?dimensions={}]'.format(extension, dimensions)},
params={'fields': 'representations'},
)
assert b'' == thumb
Copy link
Contributor

Choose a reason for hiding this comment

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

assert thumb == b''

@lukaszsocha2
Copy link
Contributor

Hi, @DaveSawyer thanks for contributing! I took over your pr because for today a new release is planned and we wanted to include your change in it.

@lukaszsocha2 lukaszsocha2 merged commit 07058be into box:main Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants