AOSSIE-Org / AOSSIE-Org/PictoPy

BUG: Orphaned Rows in image_embeddings and semantic_labels on Image Deletion

Open Beginner friendly
#1,405 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
284
Forks
680
Avg merge
7d 5h
Merged PRs (30d)
4

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

Files affected:

- `backend/app/database/image_embeddings.py`
- `backend/app/database/semantic_labels.py`

What is the problem?
Both database modules define foreign key constraints with `ON DELETE CASCADE` referencing the `images(id)` column. This is meant to ensure that when an image is deleted, its corresponding embeddings and semantic labels are deleted automatically.
However, both modules initialize database connections using `_connect()` from `app.database.images` which does not execute `PRAGMA foreign_keys = ON;`. Because SQLite disables foreign keys by default, deleting an image leaves **orphaned embeddings and semantic labels** in the database forever.

Proposed Fix:
Refactor both modules to use the `get_db_connection()` context manager from `app.database.connection` which enforces foreign key constraints correctly.

I wish to work on this issue!

### Record

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

Contributor guide

Open the contributing guide

Research direction

Read backend/app/database/image_embeddings.py and backend/app/database/semantic_labels.py, then inspect get_db_connection() in app.database.connection and the current _connect() usage from app.database.images. Replace the connection approach as described and verify that deleting an image also removes its embeddings and semantic labels without leaving orphaned rows.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlite
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.