from redis_om import Migrator, Field, JsonModel, get_redis_connection, EmbeddedJsonModel, HashModel
from pydantic import BaseModel
from typing import Optional
class Level2(EmbeddedJsonModel):
c: str
class Level1(EmbeddedJsonModel):
a: Optional[Level2]
class Model(JsonModel):
a: str = Field(default="a", index=True)
b: str = Field(index=True)
c: Level1
class Meta:
global_key_prefix = "Mine"
database = get_redis_connection(url="redis://172.17.0.2", db=0)
model_key_prefix = "Model"
Migrator().run()
a1 = Model(**{"a": "a1", "b": "b1", "c": {"a": {"c": "empty"}}})
but keep getting the following error while running:
File "/home/mmograbi/github/redis-om/test.py", line 26, in <module>
a1 = Model(**{"a": "a1", "b": "b1", "c": {"a": {"c": "empty"}}})
File "/home/mmograbi/.local/lib/python3.8/site-packages/redis_om/model/model.py", line 1510, in __init__
super().__init__(*args, **kwargs)
File "/home/mmograbi/.local/lib/python3.8/site-packages/redis_om/model/model.py", line 1131, in __init__
super().__init__(**data)
File "pydantic/main.py", line 342, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for Model
c
'NoneType' object is not subscriptable (type=type_error)
if I replace the EmbeddedJsonModel with BaseModel from pydantic it works as expected without exception.
I'm trying out the following example:
but keep getting the following error while running:
if I replace the EmbeddedJsonModel with BaseModel from pydantic it works as expected without exception.
Env: