-
Notifications
You must be signed in to change notification settings - Fork 74
[SVCS-678] Add noop for export (Functionality Only) #334
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
[SVCS-678] Add noop for export (Functionality Only) #334
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple but elegant fix 🎆 with a few 🐞 .
- Be careful about case sensitivity. I had the doubt, which was proven during local testing.
- Don't forget to
await
onasync
methods/functions. - Be more specific on logs, which help us debug.
Back to Add'l Dev 🔥 @birdbrained ~
mfr/server/handlers/export.py
Outdated
"""Export a file to the format specified via the associated extension library""" | ||
|
||
# File is already in the requested format | ||
if self.metadata.ext == ".{}".format(self.format): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double check and .lower()
the case if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the result during my testing with extra logger.info()
:
Wrong
Exported with conversion: .PDF .pdf
Correct
Exported with conversion: .JPG .2400x2400.jpeg
mfr/server/handlers/export.py
Outdated
|
||
# File is already in the requested format | ||
if self.metadata.ext == ".{}".format(self.format): | ||
await self.write_stream(self.provider.download()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, my first thought is to add a try
here but then I realize the failure should be thrown if download fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
download()
needs to be await
ed. Here is the failure:
mfr_1 | WARNING:root:No '/root/.cos/mfr-test.json' configuration file found
mfr_1 | [2018-04-26 18:38:51,921][WARNING][root]: No '/root/.cos/waterbutler-test.json' configuration file found
mfr_1 | [2018-04-26 18:38:51,930][INFO][raven.contrib.tornado.AsyncSentryClient]: Raven is not configured (logging is disabled). Please see the documentation for more information.
mfr_1 | [2018-04-26 18:38:51,935][INFO][mfr.server.app]: Listening on 0.0.0.0:7778
mfr_1 | [2018-04-26 18:39:05,366][ERROR][tornado.application]: [User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36] Uncaught exception GET /export?url=http://192.168.168.167:5000/8d9yv/?action=download%26mode=render%26direct%26public_file=False&initialWidth=848&childId=mfrIframe&parentTitle=OSF%20%7C%20test.pdf&parentUrl=http%3A%2F%2Flocalhost%3A5000%2F8d9yv%2F&format=pdf (172.18.0.1)
mfr_1 | Traceback (most recent call last):
mfr_1 | File "/usr/local/lib/python3.5/site-packages/tornado/web.py", line 1445, in _execute
mfr_1 | result = yield result
mfr_1 | File "/usr/local/lib/python3.5/site-packages/tornado/gen.py", line 1008, in run
mfr_1 | value = future.result()
mfr_1 | File "/usr/local/lib/python3.5/site-packages/tornado/concurrent.py", line 232, in result
mfr_1 | raise_exc_info(self._exc_info)
mfr_1 | File "<string>", line 3, in raise_exc_info
mfr_1 | File "/usr/local/lib/python3.5/site-packages/tornado/gen.py", line 282, in wrapper
mfr_1 | yielded = next(result)
mfr_1 | File "<string>", line 6, in _wrap_awaitable
mfr_1 | File "/code/mfr/server/handlers/export.py", line 63, in get
mfr_1 | await self.write_stream(self.provider.download())
mfr_1 | File "/code/mfr/server/handlers/core.py", line 140, in write_stream
mfr_1 | chunk = await stream.read(settings.CHUNK_SIZE)
mfr_1 | AttributeError: 'coroutine' object has no attribute 'read'
mfr_1 | [2018-04-26 18:39:05,374][INFO][tornado.access]: 172.18.0.1 - - [26/Apr/2018:18:39:05 +0800] "GET /export?url=http://192.168.168.167:5000/8d9yv/?action=download%26mode=render%26direct%26public_file=False&initialWidth=848&childId=mfrIframe&parentTitle=OSF%20%7C%20test.pdf&parentUrl=http%3A%2F%2Flocalhost%3A5000%2F8d9yv%2F&format=pdf HTTP/1.1" - - "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
And here is the correct behavior after my temporary fix:
mfr_1 | WARNING:root:No '/root/.cos/mfr-test.json' configuration file found
mfr_1 | [2018-04-26 18:52:16,412][WARNING][root]: No '/root/.cos/waterbutler-test.json' configuration file found
mfr_1 | [2018-04-26 18:52:16,423][INFO][raven.contrib.tornado.AsyncSentryClient]: Raven is not configured (logging is disabled). Please see the documentation for more information.
mfr_1 | [2018-04-26 18:52:16,432][INFO][mfr.server.app]: Listening on 0.0.0.0:7778
mfr_1 | Exported with no conversion: .pdf
mfr_1 | [2018-04-26 18:52:53,903][INFO][tornado.access]: 172.18.0.1 - - [26/Apr/2018:18:52:53 +0800] "GET /export?url=http://192.168.168.167:5000/8d9yv/?action=download%26mode=render%26direct%26public_file=False&initialWidth=848&childId=mfrIframe&parentTitle=OSF%20%7C%20test.pdf&parentUrl=http%3A%2F%2Flocalhost%3A5000%2F8d9yv%2F&format=pdf HTTP/1.1" - - "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
mfr/server/handlers/export.py
Outdated
# File is already in the requested format | ||
if self.metadata.ext == ".{}".format(self.format): | ||
await self.write_stream(self.provider.download()) | ||
logger.info('Exported with no conversion.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the extension name so that we know which type it is. This also helps us identify bugs easily.
For now, adding/updating new unit tests is not required since we will have a refactoring PR right afterwards. |
194d84b
to
7c32a2c
Compare
Ok commits squashed I think this may be ready to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and move to RTM for @felliott 🎆
Ticket
https://openscience.atlassian.net/browse/SVCS-678
Purpose
What
When MFR receives an export request where the input and output formats are the same, it should simply return the original file unmodified... unless there's another reason to export the file (i.e. image scaling).
Why
A no-op is a simple operation to support, why not do it?
Acceptance criteria
A PR to support
QA notes
Devs will test this. Dev, please add a list of affected and unaffected file types.
Build an MFR export url requesting to export a file of type foo as type foo. This should start a download of the raw file without modification. Exception: image files should respect scaling parameters.