You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Find operation on datetime field raises error --> argument of type 'datetime.datetime' is not iterable
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:6380"
class Person(HashModel):
first_name: str = Field(index=True)
last_name: str = Field(index=True)
birth_datetime: datetime.datetime = Field(index=True)
# set redis connection
Person.Meta.database = get_redis_connection(url=REDIS_DATA_URL,
decode_responses=True)
# apply migrations
Migrator().run()
# First, we create a new `person` object:
person = Person(
first_name="John",
last_name="Smith",
birth_datetime = datetime.datetime(2002, 4, 9, 9, 13)
)
# print globally unique primary key
print(person.pk)
# save person to Redis
person.save()
# get by primary key (WORKS!!!)
Person.get(person.pk)
# Find all person with first name "John" - WORKS!!
Person.find(Person.first_name == "John").all()
# find all person with birth date time with date as string - NOT WORKING!! ( Returns empty list )
Person.find(Person.birth_datetime == '2002-04-09 09:13').all()
# find all person with birth date time with date type - Not working!! ( Error: argument of type 'datetime.datetime' is not iterable )
Person.find(Person.birth_datetime == datetime.datetime(2002, 4, 9, 9, 13)).all()
The text was updated successfully, but these errors were encountered:
Ideally too the way date/time is indexed could change so that it's possible to do range queries over it (probably need to store the date/time as a timestamp for this).
Find operation on datetime field raises error --> argument of type 'datetime.datetime' is not iterable
The text was updated successfully, but these errors were encountered: