Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_highlightResult leads to serialization warnings #569

Open
kai687 opened this issue Aug 21, 2024 · 5 comments
Open

_highlightResult leads to serialization warnings #569

kai687 opened this issue Aug 21, 2024 · 5 comments

Comments

@kai687
Copy link
Contributor

kai687 commented Aug 21, 2024

I run code similar to:

import asyncio
import os

from algoliasearch.search.client import SearchClient

app_id = os.getenv("ALGOLIA_APP_ID")
api_key = os.getenv("ALGOLIA_API_KEY")
index_name = os.getenv("test-index")

async def search() -> None:
    async with SearchClient(app_id, api_key) as client:
        res = await client.save_object(
            index_name=index_name,
            body={"title": "test record"},
        )

        await client.wait_for_task(index_name=index_name, task_id=res.task_id)

        res = await client.search(
            search_method_params={
                "requests": [{"indexName": index_name, "query": "recrod"}]
            }
        )

        print(res.results[0].to_json())


if __name__ == "__main__":
    asyncio.run(search())

The output includes warnings from Pydantic:

(...)/lib/python3.12/site-packages/pydantic/main.py:415: UserWarning: Pydantic serializer warnings:
  Expected `Union[dict[str, definition-ref], dict[str, definition-ref], definition-ref, list[definition-ref]]` but got `dict` - serialized value may not be as expected
  return self.__pydantic_serializer__.to_json(
{"abTestID":null,"abTestVariantID":null,"aroundLatLng":null,"automaticRadius":null,"exhaustive":{"facetsCount":null,"facetValues":null,"nbHits":true,"rulesMatch":null,"typo":true},"exhaustiveFacetsCount":null,"exhaustiveNbHits":true,"exhaustiveTypo":true,"facets":null,"facets_stats":null,"index":"test-index","indexUsed":null,"message":null,"nbSortedHits":null,"parsedQuery":null,"processingTimeMS":1,"processingTimingsMS":{"_request":{"roundTrip":17},"getIdx":{"load":{"total":1},"total":1},"total":1},"queryAfterRemoval":null,"redirect":null,"renderingContent":{"facetOrdering":null,"redirect":null},"serverTimeMS":1,"serverUsed":null,"userData":null,"queryID":null,"page":0,"nbHits":1,"nbPages":1,"hitsPerPage":20,"hits":[{"objectID":"80834191002","_highlightResult":{"title":{"value":"test <em>record</em>","matchLevel":"full","fullyHighlighted":false,"matchedWords":["recrod"]}},"_snippetResult":null,"_rankingInfo":null,"_distinctSeqID":null}],"query":"recrod","params":"query=recrod"}

If I set attributesToHighlight to null, the warning disappears, so I assume this has something to do with trying to deserialize the _highlightResult response property.

@kai687
Copy link
Contributor Author

kai687 commented Aug 21, 2024

I imagine this might be fixed with algolia/api-clients-automation#3567

@shortcuts
Copy link
Member

I imagine this might be fixed with algolia/api-clients-automation#3567

Thanks for reporting! Is it still happening in the latest version? (4.1.1)

@kai687
Copy link
Contributor Author

kai687 commented Aug 21, 2024

Yes, this happens with 4.1.1

@shortcuts
Copy link
Member

Can confirm we can reproduce from our e2e, it's just silenced so we did not saw the warning, thanks!

@antoineleclair
Copy link

We just updated to the latest version of the package (from 3.0.0 to 4.6.2) and we now have similar warnings.

They appear when we're calling .to_dict() on a SearchResponse:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants