v2ex / remote

Remote Worker
https://www.v2ex.com/go/dev
MIT License
80 stars 4 forks source link

UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f5a1061c310> #10

Closed sentry-io[bot] closed 2 years ago

sentry-io[bot] commented 2 years ago

Sentry Issue: REMOTE-1D

UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f5a1061c310>
  File "app.py", line 431, in resize_avatar
    base_avatar = Image.open(io.BytesIO(base_avatar_data))
  File "PIL/Image.py", line 3030, in open
    raise UnidentifiedImageError(
livid commented 2 years ago

@luxiaba

We do not expect users to always upload images larger than the sizes in AvatarSize, that is why the current implementation is crashing.

livid commented 2 years ago

Commit f631306 added a test for this corner case.

If the user uploaded image is smaller, this is the originally expected behavior:

Resize to cover 24x24, 48x48, and 73x73.

But do not generate for 128x128, 256x256, and 512x512.

livid commented 2 years ago

Tests can be ran like this:

pytest -sx -vvv --cov=app tests/
luxiaba commented 2 years ago

Sorry again, I think I ve solved this problem by this commit. resize other sizes based on the max AvatarSize. If the original size is larger than the this, otherwise use the original size as the base.

livid commented 2 years ago

You can reproduce the issue with the latest test test_images_resize_avatar_1px.

livid commented 2 years ago

I added the full expected behavior in 195e6a7

As long as it can pass the test, it will be fine.

luxiaba commented 2 years ago

I've test latest commit and it's passed all testes.

I didn't know that released it in the prod in such a timely manner, and i can't observe the latest error message in time. I'm very sorry to bring you trouble.

livid commented 2 years ago

It is OK. Not your fault, and this project was open-sourced without proper tests.

We need more tests that align with the current production requirements. :)

luxiaba commented 2 years ago

maybe i can open a PR that add Github CI, in which pre-commit and testing are integrated if you wish.

livid commented 2 years ago

Yes, of course. Thanks a lot!

livid commented 2 years ago

First CI run completed successfully!