Conversation
nijel
commented
May 23, 2026
- use contenxt to work with the file
- use targettet exceptions instead of wide Exception
- use contenxt to work with the file - use targettet exceptions instead of wide Exception
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
There was a problem hiding this comment.
Pull request overview
Refactors validate_bitmap in weblate_web/models.py to use targeted Pillow exceptions instead of a broad except Exception, manages the opened image via a with block instead of try/finally, and adds a new BitmapValidationTest class covering valid PNGs, corrupted/invalid bytes, decompression-bomb headers, unsupported MIME types, and bad dimensions.
Changes:
- Introduce a
PILLOW_VALIDATION_ERRORStuple (OSError,SyntaxError,ValueError,DecompressionBombError) and use it for theopen/verifycalls, removing the broadexcept Exceptionand thesys.exc_info()traceback dance. - Use
with image:to ensure the image is closed, replacing thetry/finally: image.close(). - Add
BitmapValidationTestinweblate_web/tests.pywith helpers to generate and corrupt PNGs and tests for the success and error paths ofvalidate_bitmap.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| weblate_web/models.py | Narrows exception handling in validate_bitmap and switches to a context-managed image. |
| weblate_web/tests.py | Adds BitmapValidationTest covering valid, invalid, corrupt, oversized, unsupported, and mis-sized images. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3832 +/- ##
==========================================
+ Coverage 88.33% 88.52% +0.18%
==========================================
Files 68 68
Lines 9507 9576 +69
Branches 821 824 +3
==========================================
+ Hits 8398 8477 +79
+ Misses 836 820 -16
- Partials 273 279 +6 🚀 New features to boost your workflow:
|