Skip to content

_highlightResult leads to serialization warnings #569

@kai687

Description

@kai687

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions