AOSSIE-Org / AOSSIE-Org/PictoPy

BUG: AI tagging aborts entire batch when encountering a corrupt/unreadable image

Offen Anfängerfreundlich
#1,496 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
Python
Sterne
284
Forks
680
Ø Merge
7 T. 5 Std.
Gemergte PRs (30 T.)
4

Beschreibung

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

During the AI tagging pipeline (`image_util_classify_and_face_detect_images`), the `ObjectClassifier` safely returns `None` if `cv2.imread` fails to read an image (e.g., due to file corruption or unsupported format). However, the calling code assumes a list is always returned and immediately calls `len(classes) > 0`.

Because there is no try/except block around the loop body, this throws a `TypeError: object of type 'NoneType' has no len()` and permanently crashes the tagging process for the current folder. All subsequent valid images in the queue are skipped and left untagged.

## #Steps to Reproduce
1. Start PictoPy and ensure AI Tagging is enabled.
2. Add a folder containing multiple images, where at least one image is corrupted or is a 0-byte invalid file.
3. Observe that the indexing/tagging process stops abruptly at the corrupt image.
4. Check the backend logs to see a `TypeError` traceback originating from `if len(classes) > 0:` in `images.py`.
5. Observe that the remaining valid images in the folder are never AI-tagged.

### Expected Behavior
A corrupt image should be logged as a failure, skipped, and the AI tagging process should continue seamlessly for the remaining images in the folder.

### Actual Behavior
The entire background process aborts, leaving valid photos untagged.

### Code Pointers
- **Model Layer:** `backend/app/models/ObjectClassifier.py` (lines 17-21) returns `None` when `img is None`.
- **Calling Layer:** `backend/app/utils/images.py` (around line 170) does not check for `None` before checking `len()`.

### Suggested Fix
Update the check in `backend/app/utils/images.py` to handle the `None` case safely and wrap the loop body in a `try/except` block to prevent a single image failure from bubbling up and crashing the entire batch:
```python
if classes is not None and len(classes) > 0:
# Insert class-image pairs
```

I have isolated the root cause for this issue and would love to be assigned to submit a PR for it!

### Record

- [x] I agree to follow this project's Code of Conduct

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start in backend/app/utils/images.py around line 170 and compare its handling of the None returned by backend/app/models/ObjectClassifier.py lines 17-21. Reproduce with a folder containing a corrupt or 0-byte image plus valid images, then verify the failure is logged and skipped while later valid images are AI-tagged without a TypeError.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
opencv, python
Bereich
computer-vision, desktop
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Aktiv
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
88/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.