openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Work can be added to the same series multiple times

Open popcar2 opened this issue 8 months ago • 3 comments

Problem

While editing a work, you could add the same series multiple times, and this gets saved into the work when you finish editing.

The work still gets shown only once in the series page so it's not a serious issue, but this shouldn't be possible to prevent mistakes. At least, repeat entries should be ignored/not saved into the work.

Example work (edit to see the entries): https://openlibrary.org/works/OL40730519W/Death_Note_Notebook_Journal

Image

Reproducing the bug

  1. Edit a work
  2. In the work series section, add the same series multiple times
  3. Save
  • Expected behavior: A series that was already added not being shown in the autocomplete, or repeat entries getting discarded when saved, or an error being shown when saving
  • Actual behavior: Repeat entries are saved, which may cause issues down the line

Context

You need to be a super librarian to use work series.

Breakdown

Implementation Details (for maintainers)

Requirements Checklist

  • [ ]

Related files

Stakeholders


Instructions for Contributors

  • Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.

popcar2 avatar Mar 23 '26 14:03 popcar2

Hi, @cdrini ! I've looked into this issue and I'd like to be assigned to fix it.

This is a broad research, but will get into it more if assigned!

Problem: Currently, when the Work Edit form is submitted, code.py delegates the POST request to the generic Infogami editor (core.edit.POST). Because it's a generic save, the series array from the frontend is blindly attached to the Work object, allowing identical series keys to be saved multiple times.

Proposed Solution: Since we want to ensure duplicate series are ignored at the data level, the safest approach is to filter the series array inside the Work model right before the object is saved.

Let me know if the issue is available and if my approach is correct so I can start working on it, thanks! c:

IvanPisquiy06 avatar Mar 24 '26 03:03 IvanPisquiy06

Hi @IvanPisquiy06 I was looking into this and actually just put up a PR to address it! It adds some inline frontend duplicate checks and hardens the backend deduplication logic so random/duplicate strings don't sneak through.

Would be awesome if you and @cdrini could take a quick look at the PR and let me know your thoughts or if anything needs tweaking Happy to change directions and collaborate if you think there's a better overall way to solve this. Cheers!

Harshul23 avatar Mar 24 '26 14:03 Harshul23

Thanks for the interest folks! This is one we don't think is worth fixing. Since the UI is pretty clear when a book is added to a series (see screenshot), it's not very likely that someone would accidentally add the same book twice. So closing for now unless we start seeing this become an issue as more people use the feature.

cdrini avatar Mar 24 '26 14:03 cdrini