Closed
Description
When defining default values in a JsonModel, these values are unexpectedly being set as ExpressionProxy objects instead of the intended default values.
Expected Behavior:
Default values defined in the model should be directly set as the specified values.
Actual Behavior:
Default values are replaced with ExpressionProxy objects.
Steps to reproduce:
When running the following code:
import datetime
from typing import Optional
from redis_om import JsonModel, Field
class Customer(JsonModel):
first_name: str
last_name: str
email: str
join_date: datetime.date
age: int = Field(default=18)
bio: Optional[str] = "Super dope"
class Child(Customer):
is_new: bool = Field(default=True)
andrew = Child(
first_name="Andrew",
last_name="Brookins",
email="andrew.brookins@example.com",
join_date=datetime.date.today(),
)
print("Age Field: ", andrew.age)
print("Bio Field: ", andrew.bio)
print("Model Field:", andrew.model_dump())
produces the following output:
Age Field: <redis_om.model.model.ExpressionProxy object at 0x7fb70dcdf8e0>
Bio Field: <redis_om.model.model.ExpressionProxy object at 0x7fb70db8c160>
Model Field: {'pk': '01JCV9FESAVVNAVBG2XJSTQGNN', 'first_name': 'Andrew', 'last_name': 'Brookins', 'email': 'andrew.brookins@example.com', 'join_date': datetime.date(2024, 11, 17), 'age': <redis_om.model.model.ExpressionProxy object at 0x7fb70dcdf8e0>, 'bio': <redis_om.model.model.ExpressionProxy object at 0x7fb70db8c160>, 'is_new': True}
Additional Notes:
However, replacing JsonModel by pydantic BaseModel works fine
import datetime
from typing import Optional
from pydantic import BaseModel
from redis_om import Field
class Customer(BaseModel):
first_name: str
last_name: str
email: str
join_date: datetime.date
age: int = Field(default=18)
bio: Optional[str] = "Super dope"
class Child(Customer):
is_new: bool = Field(default=True)
andrew = Child(
first_name="Andrew",
last_name="Brookins",
email="andrew.brookins@example.com",
join_date=datetime.date.today(),
)
print("Age Field: ", andrew.age)
print("Bio Field: ", andrew.bio)
print("Model Field:", andrew.model_dump())
This code produces the following output:
Age Field: 18
Bio Field: Super dope
Model Field: {'first_name': 'Andrew', 'last_name': 'Brookins', 'email': 'andrew.brookins@example.com', 'join_date': datetime.date(2024, 11, 17), 'age': 18, 'bio': 'Super dope', 'is_new': True}
Environment
- Python: 3.10.15
- Implementation: CPython
- Platform: linux
redis-om
version: 0.3.3pydantic
version: 2.9.2
Metadata
Metadata
Assignees
Labels
No labels