AOSSIE-Org / AOSSIE-Org/PictoPy
BUG: AI tagging aborts entire batch when encountering a corrupt/unreadable image
- Langage dominant
- Python
- Étoiles
- 284
- Forks
- 680
- Merge moyen
- 7 j 5 h
- PR mergées (30 j)
- 4
Description
### 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
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- opencv, python
- Domaine
- computer-vision, desktop
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- Active
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 88/100