PictoPy icon indicating copy to clipboard operation
PictoPy copied to clipboard

BUG: Album create/update accept a blank or whitespace-only name

Open Saurabhyadav0 opened this issue 2 weeks ago • 5 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

What happened?

Bug Description

The album create and update endpoints accept a blank or whitespace-only name, so an album can be saved with an empty name ("" or " "). The name column has no such guard either, so the blank name is persisted.

Cause

In backend/app/schemas/album.py:

  • CreateAlbumRequest.name is Field(..., min_length=1) (line 25). min_length counts whitespace, so " " (length 3) passes and reaches the database as a blank name.
  • UpdateAlbumRequest.name is a plain str (line 52) with no min_length and no validator at all, so even "" passes.

The project already solved exactly this in the same file: CreateAlbumFromMemoryRequest has a check_not_blank validator (lines 42–48) that strips the value and rejects it if empty, with a comment noting "min_length counts the spaces, so ' ' would otherwise get through." That guard was simply never added to CreateAlbumRequest or UpdateAlbumRequest.

Downstream nothing catches it: the albums.album_name column is TEXT UNIQUE (no NOT NULL, no check), and db_insert_album / db_update_album write the value as-is without stripping.

Steps to reproduce

  1. Create:
    POST /albums/   {"name": "   "}
    
    → 200; an album is created whose name is only spaces.
  2. Update:
    PUT /albums/{id}   {"name": "", "is_locked": false}
    
    → 200; the album's name is now empty.

Expected behavior

Both requests should be rejected with a 422/400 when name is blank or whitespace-only, consistent with CreateAlbumFromMemoryRequest.

Suggested fix

  • Add a check_not_blank field validator (strip, then reject if empty) to CreateAlbumRequest.name and UpdateAlbumRequest.name, mirroring the existing one on CreateAlbumFromMemoryRequest, and store the stripped name.
  • Add tests for the create and update paths.

Notes

Not a duplicate of #1254 (empty/whitespace image_ids, which is already fixed) or #1612 (renaming to an existing name). This is specifically about blank/whitespace album names on create and update.

I'd like to work on this if it's approved.

Record

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

Saurabhyadav0 avatar Nov 15 '26 15:11 Saurabhyadav0

👋 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 :)

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

⚠️ Potential Duplicate Issue (Semantic Match)

This issue appears semantically similar to the following issues in AOSSIE-Org/PictoPy:

  1. BUG: Renaming an album to an existing name returns 400 with raw SQLite error (#1612, closed) https://github.com/AOSSIE-Org/PictoPy/issues/1612 Similarity: 73.7%

  2. BUG: Missing validation for empty or whitespace image_ids in Album requests (#1254, closed) https://github.com/AOSSIE-Org/PictoPy/issues/1254 Similarity: 70%

  3. BUG:Backend lets an album be locked with no password, making it permanently inaccessible (#1713, open) https://github.com/AOSSIE-Org/PictoPy/issues/1713 Similarity: 64.6%

Please review before proceeding.

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

@rohan-pandeyy I would like to work on this issue can I get assigned ?

swastiksharma45 avatar Nov 15 '26 16:11 swastiksharma45

Hey @rohan-pandeyy , can I work on this issue? It seems to be a fairly simple fix. The solution is to introduce a field validator that checks whether the album name is blank or consists entirely of whitespace characters. If so, it raises a 400/422 HTTP error response; otherwise, the request proceeds with the entered name.

The same changes need to be applied to the following classes in backend/app/schemas.py:

  1. CreateAlbumRequest
  2. CreateAlbumFromMemoryRequest
  3. UpdateAlbumRequest

The field-validator would look like this:

@field_validator("name", mode="before")
@classmethod
def validate_name_not_blank(cls, value: Any) -> Any:
    if isinstance(value, str) and not value.strip():
        raise ValueError("Album name cannot be blank or consist only of whitespace.")
    return value

sayxnn17 avatar Nov 17 '26 19:11 sayxnn17

@sayxnn17 working on it , thankyou

Saurabhyadav0 avatar Nov 18 '26 05:11 Saurabhyadav0