BUG: Album create/update accept a blank or whitespace-only name
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.nameisField(..., min_length=1)(line 25).min_lengthcounts whitespace, so" "(length 3) passes and reaches the database as a blank name.UpdateAlbumRequest.nameis a plainstr(line 52) with nomin_lengthand 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
- Create:
→POST /albums/ {"name": " "}200; an album is created whose name is only spaces. - 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_blankfield validator (strip, then reject if empty) toCreateAlbumRequest.nameandUpdateAlbumRequest.name, mirroring the existing one onCreateAlbumFromMemoryRequest, 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
👋 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 :)
⚠️ Potential Duplicate Issue (Semantic Match)
This issue appears semantically similar to the following issues in AOSSIE-Org/PictoPy:
-
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%
-
BUG: Missing validation for empty or whitespace image_ids in Album requests (#1254, closed) https://github.com/AOSSIE-Org/PictoPy/issues/1254 Similarity: 70%
-
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.
@rohan-pandeyy I would like to work on this issue can I get assigned ?
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:
CreateAlbumRequestCreateAlbumFromMemoryRequestUpdateAlbumRequest
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 working on it , thankyou