redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.12k stars 112 forks source link

`delete` will throw an exception if invoked on a non existing record. #355

Closed wiseaidev closed 2 years ago

wiseaidev commented 2 years ago

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,
    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

router = FastAPI(title=__name__)

@router.on_event("startup")
async def startup():
    await Migrator().run()
    user2 = await User(email="yo@wiseai.dev", password="P@ssW0rD").save()
    await User.find(User.email=="yo@wiseai.dev").delete()
    await User.find(User.email=="yo@wiseai.dev").delete()

Output:

raise response from None
aioredis.exceptions.ResponseError: wrong number of arguments for 'del' command
dvora-h commented 2 years ago

Great catch! thanks for reporting this. I opened a PR to fix it #372