Skip to content

Commit

Permalink
Fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrini committed Nov 24, 2022
1 parent f12a00e commit fd52403
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions openlibrary/plugins/worksearch/schemes/works.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import re
import sys
from typing import Any, Optional
from typing import Any, Optional, cast

import luqum.tree
import web
Expand Down Expand Up @@ -421,20 +421,23 @@ def convert_work_query_to_edition_query(work_query: str) -> str:
return params

def add_non_solr_fields(self, non_solr_fields: set[str], solr_result: dict) -> None:
from openlibrary.plugins.upstream.models import Edition

# Augment with data from db
edition_keys = [
ed_doc['key']
for doc in solr_result['response']['docs']
for ed_doc in doc.get('editions', {}).get('docs', [])
]
editions = web.ctx.site.get_many(edition_keys)
editions = cast(list[Edition], web.ctx.site.get_many(edition_keys))
ed_key_to_record = {ed.key: ed for ed in editions if ed.key in edition_keys}

from openlibrary.book_providers import get_book_provider

for doc in solr_result['response']['docs']:
for ed_doc in doc.get('editions', {}).get('docs', []):
ed = ed_key_to_record.get(ed_doc['key'])
assert ed
for field in non_solr_fields:
val = getattr(ed, field)
if field == 'providers':
Expand Down

0 comments on commit fd52403

Please sign in to comment.