From 416b82fc237fb6e22a5553c059df0ff3c16e4735 Mon Sep 17 00:00:00 2001 From: Daniel Bernstein Date: Tue, 14 Jan 2025 10:42:56 -0800 Subject: [PATCH] Ensure that empty subtitles - ie those with a value of None - are set to null in the database rather than the string "None" --- ...c800cc42184a_set_none_subtitles_to_null.py | 23 +++++++++++++++++++ src/palace/manager/core/opds2_import.py | 6 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 alembic/versions/20250114_c800cc42184a_set_none_subtitles_to_null.py diff --git a/alembic/versions/20250114_c800cc42184a_set_none_subtitles_to_null.py b/alembic/versions/20250114_c800cc42184a_set_none_subtitles_to_null.py new file mode 100644 index 000000000..f047a7074 --- /dev/null +++ b/alembic/versions/20250114_c800cc42184a_set_none_subtitles_to_null.py @@ -0,0 +1,23 @@ +"""Set none subtitles to null + +Revision ID: c800cc42184a +Revises: 579786fecbf4 +Create Date: 2025-01-14 18:36:21.116427+00:00 + +""" + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "c800cc42184a" +down_revision = "579786fecbf4" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.execute("update editions set subtitle = null where subtitle = 'None'") + + +def downgrade() -> None: + pass diff --git a/src/palace/manager/core/opds2_import.py b/src/palace/manager/core/opds2_import.py index 857a0cf2d..535a715db 100644 --- a/src/palace/manager/core/opds2_import.py +++ b/src/palace/manager/core/opds2_import.py @@ -630,7 +630,11 @@ def _extract_publication_metadata( self.log.debug(f"Started extracting metadata from publication {publication}") title = str(publication.metadata.title) - subtitle = str(publication.metadata.subtitle) + subtitle = ( + str(publication.metadata.subtitle) + if publication.metadata.subtitle + else None + ) languages = first_or_default(publication.metadata.languages) derived_medium = self._extract_medium_from_links(publication.links)