redis-om-python
redis-om-python copied to clipboard
Optional[int] raise error if missing
If I have a model with the following field: number: Optional[int]
I can create a record without the number. But, when I'll call model.get(pk) - I'll get an error: value is not a valid integer (type=type_error.integer)
Just to be clear, this issue exist for other data types as well (like datetime, float, etc).
Here sample code to replicate this issue:
import datetime
from datetime import datetime
from typing import Optional
from redis_om import Field, HashModel, Migrator, get_redis_connection
# This Redis instance is tuned for durability.
REDIS_DATA_URL = "redis://localhost:6379"
class Person(HashModel):
first_name: str = Field(index=True)
last_name: str = Field(index=True)
emp_no: int = Field(index=True, sortable=True)
lastDate: Optional[datetime]
dailyWage: Optional[float]
workDayPerWeek: Optional[int]
# set redis connection
Person.Meta.database = get_redis_connection(url=REDIS_DATA_URL,
decode_responses=True)
# apply migrations
Migrator().run()
# add employe
emp_no = 999
person = Person(first_name="John" + str(emp_no), last_name="Doe", emp_no=emp_no)
person.save()
# get employee
result = Person.find().all()
This is being worked on - but in the meantime if you can, this issue only applies to HashModels and you can swap it for a JsonModel and it will work