-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 #19110: Copy translation's target exploration images regardless if submitter uploaded new images or not #20188
Conversation
…dless if there are new images introduced in the translation suggestion or not.
…copy from a source asset that does not exist.
Hi @vojtechjelinek, @DubeySandeep, @kevintab95, PTAL at this PR, it modifies files in jobs or platform folders. |
Assigning @chris7716 for the first pass review of this PR. Thanks! |
@chris7716 @kevintab95 If the only datastore change is to raise an error when copying files in the case of the given source asset not existing, do I still have to do server testing for this behavior? If so, then I think I'll just revert this behavior back to what it originally was, since I'm aiming to get this PR merged by April 30th latest. |
core/controllers/suggestion.py
Outdated
filenames: list(str). The image filenames. | ||
""" | ||
suggestion_image_context = suggestion.image_context | ||
# TODO(#10513): Find a way to save the images before the suggestion is |
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.
Just to check, is this still relevant here? From reading this it's a bit unclear when the suggestion is created exactly, and what we actually want to do here.
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.
@seanlip Issue #10513 is still open as of now. Although I personally don't see why we should save the images before the suggestion is saved, with the exception that images for question suggestions are saved before saving the question suggestion. I think that images should be saved as the suggestion is saved, since those images are a part of the suggestion and it doesn't make sense for images uploaded by the translation submitter to exist without the suggestion existing first. What do you think?
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.
Yes, I think that sounds reasonable to me too. I think we can close that issue since it doesn't provide justification and we can't understand why it makes conceptual sense to do it ... I'll leave a note there.
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.
(Btw the comments in #10475 have some interesting context on the existing implementation, e.g. https://docs.google.com/document/d/1kGvPjYnW9ArYKtzxYOmFbp7MA-A45B3znRWFIlaEGVo/edit#heading=h.xyfn6zlrzj3e and #10475 (comment)
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.
@seanlip I removed the TODO comment.
core/controllers/suggestion.py
Outdated
) | ||
except ValueError as error: | ||
raise Exception( | ||
'There are images in the target exploration that are ' |
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.
This is somewhat unclear and I wouldn't know what to do if I saw this error. Could you please explain it more simply?
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.
An image in the submitted translation's original content named "{filename}" cannot be found. Please save it to the backend file system at /exploration/{exp_id}/assets/image/ before submitting this translation again.
For example, if an image with filename img.png
was part of submitted translation's target exploration with id s5Fr3Zd
, then the error message will read: An image in the submitted translation's original content named "img.png" cannot be found. Please save it to the backend file system at /exploration/s5Fr3Zd/assets/image/ before submitting this translation again.
Also, I think I should move the copy operation of old images before the save operation of new images. That way if the images aren't copied successfully, then we don't save the new images either.
@seanlip What do you think?
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.
Yup, that's much clearer, thanks!
I don't have a strong opinion on which order we should do the copy/save in -- I'm not sure why we'd want to test copying first in particular. One suggestion to keep things clean might be to fetch all the necessary images first (from both the original content and the new suggestion), and then save all of them to the correct paths in one for loop.
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.
@seanlip I restructured the error message.
core/controllers/suggestion.py
Outdated
files, suggestion, new_image_filenames | ||
) | ||
|
||
self._copy_images_from_target_exploration_to_translation(suggestion) |
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.
I'm a bit confused ... why do we upload and then copy? I.e. why isn't adding the images that were part of the translation suggestion into the suggestion's directory sufficient?
I would have thought that we would:
(a) add the images that were sent as image data into the suggestion's directory
(b) copy the images that were part of the translation suggestion's text, but that were not sent as image data, into the suggestion's directory
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.
@seanlip For context, the copy tool creates an image in the HTML string, whose filepath
points to the original image's filepath. The original image is an image in a card's content belonging to the target exploration. The intent of this algorithm isn't to upload images created using the copy tool. Instead, we are trying to copy the original images for the translation suggestion to use as assets. Since the images created using the copy tool have the same filename
as the original image, this will also allow the images created using the copy tool to load when reviewing the translation. In short, we save images uploaded directly from the translation submitter, and then we copy the original images within the target exploration's card's content for the suggestion to use later on.
I think the highlighted method name is not clear about this. I think the name _copy_images_in_target_exploration_content_to_translation(suggestion)
would be better since it better explains what images I'm referring to.
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.
Ah yup, as long as we just use the images in the translation suggestion's card, then that seems fine. I just want to ensure we aren't copying "extra" images that aren't part of the card. Thanks!
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.
@seanlip I renamed the method responsible for copying the images in the target exploration content.
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 for 4 codeowner files. Thanks @StephenYu2018!
Assigning @lkbhitesh07 for code owner reviews. Thanks! |
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.
Thanks @StephenYu2018, replied to both comments (including here).
response_dict['error']) | ||
self.logout() | ||
|
||
def test_saves_new_images_in_translation_that_were_copied_from_target_exploration( # pylint: disable=line-too-long |
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.
@StephenYu2018 Sorry, I can't find that test ... which line of code are you referring to?
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.
Thanks @StephenYu2018! LGTM, we can defer future work to #20232 as discussed.
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 for codeowner files.
Unassigning @chris7716 since they have already approved the PR. |
Hi @StephenYu2018, this PR is ready to be merged. Please address any remaining comments prior to merging, and feel free to merge this PR once the CI checks pass and you're happy with it. Thanks! |
@seanlip @chris7716 @kevintab95 Can you merge this PR now? The CI checks have passed. |
Overview
This PR fixes #19110.
This PR does the following:
SuggestionHandler
to copy of translation's target exploration images within GCS file system from/exploration/...
to/exploration_suggestions/...
SuggestionHandler.post()
cloud_storage_services.py
anddev_mode_storage_services.py
throw aValueError
if source asset does not exist at given filepathcloud_storage_services_test
: Throws value error when source asset does not exist at filepathsuggestion_test
:test_saves_new_images_in_translation_that_were_copied_from_target_exploration
test_raises_exception_if_target_exploration_image_is_not_in_target_exploration_assets
The original bug occurred because images in the translation's target exploration were copied in GCS File System from
/exploration/...
to/exploration_suggestions/...
only when the translation submitter uploaded new images to the translation text. If a translation reviewer were to review that submitted translation, the images would not load since they must be fetched from/exploration_suggestions/...
.The PR that introduced this bug is #16532, in particular this commit. Prior to these changes, suggestion images were uploaded as long as it wasn't a question suggestion (in other words, a translation suggestion). Those changes introduced a check to only upload suggestion images if the list of new images introduced by the translation submitter was not empty. It's also possible that it was trying to check that the list of new images wasn't
None
.Essential Checklist
Please follow the instructions for making a code change.
Proof that changes are correct
Before:
After:
Proof of changes on desktop with slow/throttled network
issue-19110-slow-proof.mp4
Proof of changes on mobile phone
issue-19110-mobile-proof.mp4
Proof of changes in Arabic language
issue-19110-arabic-proof.mp4
PR Pointers