Closed wasperen2 closed 1 month ago
Describe the bug If the value of an optional property is None, storing a Model fails
None
Model
To Reproduce Running the following code:
import uuid from typing import Optional from pydantic import Field from pydantic_redis import Store, RedisConfig, Model class Child(Model): _primary_key_field = "id" id: str = Field( default_factory=lambda: uuid.uuid4().hex, ) name: str = Field() class Parent(Model): _primary_key_field = "id" id: str = Field( default_factory=lambda: uuid.uuid4().hex, ) name: str = Field() child: Optional[Child] = Field(default=None) store = Store( name="does_none_work", redis_config=RedisConfig(host='localhost', port=6379, db=6) ) store.register_model(Child) store.register_model(Parent) parent = Parent(name="bong bing") Parent.insert(parent) parents_retrieved = Parent.select(ids=[parent.id]) print(parents_retrieved)
Fails with the following exception:
AttributeError: type object 'NoneType' has no attribute 'get_primary_key_field'
Expected behavior One would expect the Parent object to be just stored into Redis with the Optional property left to None.
Optional
Describe the bug If the value of an optional property is
None
, storing aModel
failsTo Reproduce Running the following code:
Fails with the following exception:
Expected behavior One would expect the Parent object to be just stored into Redis with the
Optional
property left toNone
.