PictoPy icon indicating copy to clipboard operation
PictoPy copied to clipboard

BUG: Add images to album: success message shows requested count, not number actually added

Open sathvikn113 opened this issue 2 weeks ago • 4 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

What happened?

I was reading through the album routes and noticed the "Added N images" message uses the length of the request, not what was actually inserted.

Where

backend/app/routes/albums.py (~line 375):

db_add_images_to_album(album_id, body.image_ids)
request_metadata_export(app_state)
return SuccessResponse(
    success=True, msg=f"Added {len(body.image_ids)} images to album"
)

db_add_images_to_album() in backend/app/database/albums.py only inserts IDs that exist in images, uses INSERT OR IGNORE, and returns nothing, so the route can't know how many rows were really added.

What I think happens

  • One existing ID plus one nonexistent ID: one row should be inserted, but the message should say "Added 2 images to album".
  • An ID already in the album is skipped by INSERT OR IGNORE but should still be counted in the message.
  • A repeated ID in one request should be counted twice in the message but inserted once.

I found this by reading the code and the existing tests. The existing 404 test mocks the DB function, so mixed valid/invalid IDs aren't covered.

Possible fix

Return cursor.rowcount from db_add_images_to_album() and use it in the route message, plus a route test and a DB test for the mixed and already-in-album cases.

Record

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

sathvikn113 avatar Nov 17 '26 18:11 sathvikn113

👋 Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)

Discussions are carried on Discord.

Instead of commenting here, join the AOSSIE Discord server and go to Projects → PictoPy.

If you find this project useful, a GitHub star would be appreciated.

github-actions[bot] avatar Nov 17 '26 18:11 github-actions[bot]

Hi! I'd like to work on this issue.

I've reviewed the problem and the proposed solution. I can work on returning the actual inserted row count from db_add_images_to_album() and updating the route to use that value.

I'll also add database-level and route-level regression tests covering nonexistent IDs, already-added images, and duplicate IDs in the same request.

Please let me know if I can take this up.

avika269 avatar Nov 18 '26 05:11 avika269

Hey, I went through the code and found the exact spot causing this.

The issue is in db_add_images_to_album() — it runs INSERT OR IGNORE but never returns anything, so the route has no choice but to use len(body.image_ids) which is just the number you sent, not what actually got saved.

Fix is two small changes:

After executemany in db_add_images_to_album(), save cursor.rowcount and return it In the route, use that returned number in the message instead of len(body.image_ids) This handles all three cases from the issue — nonexistent IDs get filtered before the insert, already-in-album IDs get skipped by INSERT OR IGNORE, and duplicate IDs in the same request only insert once. All three now show the real count.

Will open a PR shortl

riyanshbhosale avatar Nov 22 '26 13:11 riyanshbhosale

Hi @riyanshbhosale You are supposed open a PR only after you are assigned to the particular issue. So you can close it for now.

sathvikn113 avatar Nov 23 '26 05:11 sathvikn113