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

Update to fix view on image validation failure #10009

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jimchamp
Copy link
Collaborator

@jimchamp jimchamp commented Nov 8, 2024

Follow-up to #9966

Fixes "Unable to render this page" message being rendered in cover modal when image validation fails.

Technical

Adds validate method to image validator. Replaces existing image validation calls with a single validate call in the upload method.

Validation errors are now propagated from upload to the image upload handler. When a validation error occurs, the covers/add template is rendered with an error message.

Testing

Attempt to upload an invalid image to the covers service. Expect to see a generic error message.

An invalid image has at least one of the following properties:

  • Is greater than 10MB size
  • Ends with an invalid file extension
  • Is not actually an image

Screenshot

Screenshot 2024-11-07 171051

Stakeholders

Adds `validate` method to image validator.  Replaces
existing image validation calls with a single `validate`
call in the `upload` method.

Validation errors are now propagated from `upload` to the
image upload handler.  When a validation error occurs, the
`covers/add` template is rendered with an error message
@cdrini cdrini self-assigned this Nov 11, 2024
@@ -88,18 +96,10 @@ def upload(self, key, i):
olid = key.split("/")[-1]

if i.file is not None and hasattr(i.file, 'file'):
file_data = i.file.file
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure we want to access i.file.file multiple times; I wonder if it might have side effects / not be cached. Having validate take the filename and the file data seems like a quick way to avoid it, or we can try to find a way to verify that calling it multiple times is ok.

data = self.upload(key, i)
try:
data = self.upload(key, i)
except ValueError as e:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, this except now covers more code than before, and ValueError is a somewhat generic error that can also be thrown by native python. I think we now might need to make a custom ImageValidationError to avoid accidentally masking unrelated bugs/ValueErrors.

@cdrini cdrini added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants