From aa690d4ac4ac3b2a58b09efe95836ca30b8a53f9 Mon Sep 17 00:00:00 2001 From: mariomitte Date: Mon, 31 Aug 2026 10:54:40 +0200 Subject: [PATCH] fix: increase image megapixel limit from 8 to 30 MP to include standard phone photos Previous limit of 8 MP was rejecting standard smartphone photos (12-20 MP), causing service record PDFs/DOCX documents to be generated without photos. This was a regression from the image timeout fix: the megapixel guard was designed to prevent processing of pathologically large files (preventing worker timeouts), but the threshold was set too aggressively. Increase limit to 30 MP to allow standard device cameras while still rejecting extreme outliers that would cause timeout/OOM. Add regression test test_compress_image_for_docx_keeps_standard_phone_photos to verify 12 MP photos are accepted. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../fleet/tests/test_work_order_images_endpoint.py | 12 ++++++++++++ backend/modules/fleet/views.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/modules/fleet/tests/test_work_order_images_endpoint.py b/backend/modules/fleet/tests/test_work_order_images_endpoint.py index 37e00e5..cbfd21d 100644 --- a/backend/modules/fleet/tests/test_work_order_images_endpoint.py +++ b/backend/modules/fleet/tests/test_work_order_images_endpoint.py @@ -29,6 +29,7 @@ from modules.fleet.tasks import build_monthly_archive_cached_task from modules.fleet.views import ( _build_monthly_servicer_report_rows, _calculate_daily_quantity_from_hours, + _compress_image_for_docx, _work_order_related_tasks_queryset, ) @@ -240,6 +241,17 @@ class WorkOrderImagesEndpointTests(TestCase): self.assertIn('additional_costs_table', payload) self.assertEqual(payload['additional_costs_table']['total_for_payout'], '5.00') + def test_compress_image_for_docx_keeps_standard_phone_photos(self): + file = BytesIO() + Image.new('RGB', (4000, 3000), color='blue').save(file, format='JPEG', quality=85) + file.seek(0) + uploaded = SimpleUploadedFile('phone-12mp.jpg', file.getvalue(), content_type='image/jpeg') + + result = _compress_image_for_docx(uploaded) + + self.assertIsNotNone(result) + self.assertGreater(len(result.getvalue()), 0) + def test_work_order_related_tasks_queryset_excludes_other_work_orders_for_same_vehicle(self): other_work_order = WorkOrder.objects.create( vehicle=self.vehicle, diff --git a/backend/modules/fleet/views.py b/backend/modules/fleet/views.py index 9740c84..d39fb6b 100644 --- a/backend/modules/fleet/views.py +++ b/backend/modules/fleet/views.py @@ -464,7 +464,7 @@ def _resolve_service_report_tasks(work_order, task_id): return [selected_task], selected_task -_COMPRESS_IMAGE_MAX_MEGAPIXELS = 8 # preskači slike iznad 8 MP; sprječava timeout i OOM +_COMPRESS_IMAGE_MAX_MEGAPIXELS = 30 # preskači tek vrlo velike slike (>30 MP); standardni telefoni 12–20 MP ostaju uključeni def _compress_image_for_pdf(image_field, max_width=800, quality=75):