redis-om-python icon indicating copy to clipboard operation
redis-om-python copied to clipboard

Optional field in a JSON model may cause indexing to fail

Open simonprickett opened this issue 3 years ago • 3 comments

It appears that making a field optional in a JSON model may cause indexing of the resulting JSON to fail... example model - description field here causes indexing fails.

from pydantic import validator
from aredis_om import (Field, JsonModel, EmbeddedJsonModel)
from typing import List, Optional


class TaskAssignee(EmbeddedJsonModel):
    user_id: str = Field(index=True)


class Task(JsonModel):
    name: str = Field(index=True)
    status: str = Field(index=True)
    description: Optional[str] = Field(index=True, full_text_search=True)
    assigned_to: Optional[List[TaskAssignee]] = []
127.0.0.1:6379> ft.info :components.task.model.Task:index
 1) index_name
 2) :components.task.model.Task:index
...
 9) num_docs
10) "0"
...
37) hash_indexing_failures
38) "1"

simonprickett avatar Jan 21 '22 20:01 simonprickett

Removing Optional here fixed the indexing. full_text_search wasn't an issue.

simonprickett avatar Jan 21 '22 20:01 simonprickett

Not because the Optional, because there is no default value. if you make a default value it will work either with Optional or without it.

Currently you have to make default for optional values.

gam-phon avatar Jan 26 '22 05:01 gam-phon

@gam-phon thanks!

simonprickett avatar Feb 02 '22 12:02 simonprickett