From 44052741d3caca9fea899386e2f577c7a762a40b Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Fri, 30 Oct 2026 18:37:50 -0600 Subject: [PATCH] An author or subject beginning with a non-ASCII capital finds its collection (#902) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lookup compared SQLite's lower(name), which folds only ASCII, with Python's str.lower(), which folds Unicode. "Édouard Hospitalier" never matched its own collection, so the doc modeler inserted a duplicate, hit the unique constraint, and re-extracted and failed on that doc on every modeler run. Both sides now use SQLite's lower(). Co-authored-by: Claude Opus 5.5 --- modules/docs/lib.py | 6 ++++-- modules/docs/test/test_lib.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/docs/lib.py b/modules/docs/lib.py index 3cb67253..903e1a25 100644 --- a/modules/docs/lib.py +++ b/modules/docs/lib.py @@ -210,7 +210,8 @@ def get_or_create_author_collection(session: Session, author_name: str) -> Optio author_name = author_name.strip() collection = session.query(Collection).filter( - func.lower(Collection.name) == author_name.lower(), + # Both sides use SQLite's lower(), which folds only ASCII; Python's lower() would miss 'Édouard'. + func.lower(Collection.name) == func.lower(author_name), Collection.kind == 'author', ).first() if not collection: @@ -228,7 +229,8 @@ def get_or_create_subject_collection(session: Session, subject_name: str) -> Opt subject_name = subject_name.strip() collection = session.query(Collection).filter( - func.lower(Collection.name) == subject_name.lower(), + # Both sides use SQLite's lower(), which folds only ASCII; Python's lower() would miss 'Édouard'. + func.lower(Collection.name) == func.lower(subject_name), Collection.kind == 'subject', ).first() if not collection: diff --git a/modules/docs/test/test_lib.py b/modules/docs/test/test_lib.py index f83bd1cf..832547ab 100644 --- a/modules/docs/test/test_lib.py +++ b/modules/docs/test/test_lib.py @@ -213,6 +213,16 @@ def test_get_or_create_author_collection_case_insensitive(test_session): assert col1.id == col2.id == col3.id +@pytest.mark.parametrize('get_or_create', [get_or_create_author_collection, get_or_create_subject_collection]) +def test_get_or_create_collection_non_ascii(test_session, get_or_create): + """A name beginning with a non-ASCII capital finds its existing collection.""" + col1 = get_or_create(test_session, 'Édouard Hospitalier') + test_session.commit() + col2 = get_or_create(test_session, 'Édouard Hospitalier') + col3 = get_or_create(test_session, 'ÉDOUARD HOSPITALIER') + assert col1.id == col2.id == col3.id + + @pytest.mark.asyncio async def test_search_authors_by_name(test_session): """Search for author collections by partial name."""