Open
Description
Code to reproduce the issue:
from typing import Optional, Any
from fastapi import FastAPI
from pydantic import BaseModel, Field as PydanticField, EmailStr
import datetime
from aredis_om import (
Field,
HashModel,
JsonModel,
Migrator,
get_redis_connection
)
redis_conn = get_redis_connection(
url=f"redis://localhost:6379",
decode_responses=True
)
class User(HashModel):
first_name: Optional[str] = Field(index=True)
last_name: Optional[str] = Field(index=True)
email: EmailStr = Field(index=True)
password: str = Field(index=True)
created_on: Optional[datetime.datetime] = Field(default_factory=datetime.datetime.now)
class Meta:
database = redis_conn
class Contact(JsonModel):
user: User = Field(index=True)
contact: User = Field(index=True)
message: Optional[str] = Field(index=True, default="yo")
created_on: Optional[datetime.datetime] = Field(default_factory=datetime.datetime.now)
class Meta:
database = redis_conn
router = FastAPI(title=__name__)
@router.on_event("startup")
async def startup():
await Migrator().run()
user1 = await User(email="[email protected]", password="S3C11R3P@ssW0rD").save()
user2 = await User(email="[email protected]", password="P@ssW0rD").save()
contact1 = await Contact(user=user1, contact=user2).save()
contact2 = await Contact.find((Contact.user.email == "[email protected]") & (Contact.contact.email == "[email protected]")).all()
print(contact2)
However, the following expressions work as expected:
contact2 = await Contact.find((Contact.user.email == "[email protected]") & (Contact.message == "yo")).all()
contact2 = await Contact.find(Contact.user.email == "[email protected]").all()
This confirms my hypothesis that a JsonModel
object can index at most one HashModel
field. Is that intentional or a bug?
Metadata
Metadata
Assignees
Labels
No labels