Repository navigation
Fix custom property review findings - #387
Open
chapmanjacobd wants to merge 27 commits into
Open
chapmanjacobd wants to merge 27 commits into
chapmanjacobd wants to merge 27 commits into
Conversation
- 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.
There was a problem hiding this comment.
🟡 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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Follow-up to #369, fixing the issues found while reviewing the merged custom properties work.
Safety
calibredbonly after closing the library session, with a 120 s timeout, so Calibre is not blocked by an open SQLite transaction.toggle_ccnow loads the book throughget_filtered_book, updateslast_modified, queues the metadata backup, invalidates the Kobo sync entry and rolls back on error.cc_classes) and their sidebar setting.Correctness
0.5step and detail/list/listen render the fractional value next to the stars (rating_starsfilter) instead of truncating a stored9to8on the next save.parse_custom_column_value()for web and OPDS:1/true/yesmap toTrue, invalid values return 404.commentscolumns 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
table.jshandlers were still present).Tests
tests/functional/test_custom_columns.pycovers the missingcustom_columnstable, browseable-type/unknown-class filtering, sidebar settings, mapping removal and URL value parsing.pytest tests/functional/test_custom_columns.pyreports 5 passed.