Skip to content

Fix custom property review findings - #387

Open
chapmanjacobd wants to merge 27 commits into
iiab:masterfrom
chapmanjacobd:customcolumns
Open

chapmanjacobd wants to merge 27 commits into
iiab:masterfrom
chapmanjacobd:customcolumns

Conversation

@chapmanjacobd

Copy link
Copy Markdown
Member

Follow-up to #369, fixing the issues found while reviewing the merged custom properties work.

Safety

  • Refuse to delete a custom column that is configured as the read-status column or the view-restriction column (deleting it emptied every book list and broke read status). The label is validated and the column must exist.
  • Run calibredb only after closing the library session, with a 120 s timeout, so Calibre is not blocked by an open SQLite transaction.
  • toggle_cc now loads the book through get_filtered_book, updates last_modified, queues the metadata backup, invalidates the Kobo sync entry and rolls back on error.
  • Forget deleted columns (cc_classes) and their sidebar setting.

Correctness

  • Half-star custom ratings are preserved: the edit/search inputs use a 0.5 step and detail/list/listen render the fractional value next to the stars (rating_stars filter) instead of truncating a stored 9 to 8 on the next save.
  • Browse values are ordered in SQL (numeric for numeric columns, case-insensitive for text/enumeration) instead of lexicographically in Python.
  • Shared parse_custom_column_value() for web and OPDS: 1/true/yes map to True, invalid values return 404.
  • comments columns are no longer offered in the sidebar/OPDS (their values are not URL safe). Columns whose mapping is not loaded in this worker are ignored, and the browseable list is cached per request.

UI

  • The custom property label is an editable, validated field, so display names without Latin letters can be created and label collisions resolved.
  • Restored the "Add Allowed/Denied custom column values" buttons in the standard theme (the backend and table.js handlers were still present).
  • The admin page builds a view model instead of mutating ORM rows, and notes that sidebar visibility follows the Categories section and that other worker processes need a restart.

Tests

  • tests/functional/test_custom_columns.py covers the missing custom_columns table, browseable-type/unknown-class filtering, sidebar settings, mapping removal and URL value parsing. pytest tests/functional/test_custom_columns.py reports 5 passed.

- limit sidebar/OPDS browsing to column types whose values are URL safe
- cache the browseable columns for the request
- keep the app usable when metadata.db has no custom_columns table
- add remove_db_cc_class() so deleted columns disappear from cc_classes
- close the library session before running calibredb, with a timeout
- validate the property label and refuse to delete the read/restriction column
- forget the deleted column and its sidebar setting
- render the property list without mutating ORM rows
- reject sidebar toggles for columns that are not browseable
- respect book visibility like the other edit endpoints
- update last_modified, queue the metadata backup and drop the Kobo sync entry
- roll back and log the real exception on failure
- accept 1/true/yes for bool columns and return 404 for invalid values
- order browse values in the database instead of sorting formatted text
- keep the rating value on category entries for star rendering
- fix the printf-style error log in update_view
The star widget only offers whole stars, so saving any field rewrote e.g. a
Calibre value of 9 as 8. Use a 0.5-step number input again and render the
fractional value next to the stars instead of truncating it.
The label was a hidden field derived from the display name, so names without
Latin letters could never be created and collisions could not be resolved.
Also only offer sidebar browsing for column types that support it.
The buttons were dropped from the standard theme while the admin endpoints and
table.js handlers are still in place, leaving view restrictions unconfigurable.
@holta
holta requested a balanced review from Copilot November 17, 2026 15:57
@holta holta added bug Something isn't working enhancement New feature or request labels Nov 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Outstanding critical issues can break book listings after custom-column deletion and corrupt the default access policy inherited by new users.

4 open issues
What changed in this PR

Follow-up to #369 that hardens Calibre-Web’s custom-property management and improves consistency across editing, browsing, and OPDS.

Changes:

  • Protects configured columns from deletion and adds session cleanup and timeouts around calibredb.
  • Preserves half-star ratings, orders browse values in SQL, and centralizes URL-value parsing.
  • Refines administration controls and sidebar filtering, with focused regression tests.
File Description
tests/​functional/​test_custom_columns.py Adds filtering, mapping-removal, and parsing coverage.
cps/​web.py Uses shared parsing, SQL ordering, and raw rating values.
cps/​themes/​standard/​templates/​user_edit.html Restores user custom-column restriction controls.
cps/​themes/​standard/​templates/​search_form.html Allows half-star custom-rating searches.
cps/​themes/​standard/​templates/​listenmp3.html Uses shared custom-rating rendering.
cps/​themes/​standard/​templates/​list.html Renders ratings without truncating fractional values.
cps/​themes/​standard/​templates/​detail.html Uses shared custom-rating rendering.
cps/​themes/​standard/​templates/​config_view_edit.html Restores default custom-column restriction controls.
cps/​themes/​standard/​templates/​book_edit.html Preserves half-star ratings during editing.
cps/​themes/​caliblur/​templates/​book_edit.html Allows the lowest half-star rating.
cps/​templates/​custom_properties.html Adds editable labels and clarifies sidebar and worker behavior.
cps/​render_template.py Clarifies the shared custom-property visibility setting.
cps/​opds.py Uses shared custom-column URL parsing.
cps/​jinjia.py Adds a reusable rating display filter.
cps/​helper.py Centralizes custom-column URL-value conversion.
cps/​editbooks.py Adds visibility checks and metadata bookkeeping to boolean toggles.
cps/​db.py Adds registry cleanup and request-cached browsing filters.
cps/​admin.py Adds deletion safeguards, bounded subprocess execution, and an admin view model.

Review effort: Balanced

Comment thread cps/db.py Resolved
Comment thread cps/editbooks.py Resolved
Comment thread cps/helper.py Resolved
AlchemyEncoder read every mapped attribute, including the relationship left behind for a custom column that was removed from metadata.db. That queried a missing table and failed /ajax/listbooks. Skip attributes whose column is no longer registered in cc_classes and read attributes inside the error guard.
Adding an allowed default custom column value seeded the list from the denied values, and adding a denied value seeded it from the allowed values, discarding and copying the wrong list.
Toggling a boolean custom column changes book metadata shared by every user, so remove the Kobo sync entries for all users like the regular edit path does.
parse_custom_column_value treated every unrecognized token as false. Accept the supported true and false spellings explicitly and raise ValueError for anything else so web and OPDS return 404.
Cover skipping deleted custom columns in AlchemyEncoder, keeping allow/deny restriction lists separate, and rejecting invalid boolean values.
The admin template only existed in cps/templates, but render_title_template
looks for theme templates without a fallback, so /admin/customproperties
returned 500. Move it to the standard theme and let caliblur extend it.

Also make the caliblur sidebar honour url_kwargs, and give its list page
the same custom-property links and rating rendering as the standard theme.
Updating the books row fires books_update_trg, which calls title_sort().
toggle_cc updated last_modified without registering the function, so a fresh
session failed with 'no such function: title_sort' and returned 400.
Direct CustomColumns queries still crashed on libraries without a
custom_columns table. Add CalibreDB.get_all_cc_columns() and use it from
book editing, deletion, enum lookups, kepubify and metadata backup.
- Look up properties through get_all_cc_columns so admin pages survive a
  missing custom_columns table.
- Log the full calibredb failure and flash only its useful last line instead
  of a Python traceback.
- Reject duplicate labels and display names before calling calibredb, and
  quote both label and name for Windows.
- Ignore blank custom column restrictions, reject values containing commas
  before they are split, and remove a value from the opposite allow/deny
  list so contradictory restrictions cannot silently hide books.
List links include microseconds when Calibre stores them, but parsing
truncated to 19 characters and compared against the full value, so the
result page was empty. Accept fractional seconds and date-only values, and
reject non-finite floats instead of generating empty result pages.
SQLite's built-in lower() only folds ASCII, so accented values sorted after
lowercase Latin values. Register Calibre-Web's lower() before building the
custom property list query.
Cover the guarded column loader, datetime and float URL values, restriction
validation and the title_sort registration required by bool toggling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants