Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wiseaidev opened this issue Aug 17, 2022 · 1 comment · Fixed by #372
Closed

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

wiseaidev opened this issue Aug 17, 2022 · 1 comment · Fixed by #372

Comments

@wiseaidev
Copy link
Contributor

wiseaidev commented Aug 17, 2022

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="[email protected]", password="P@ssW0rD").save()
    await User.find(User.email=="[email protected]").delete()
    await User.find(User.email=="[email protected]").delete()

Output:

raise response from None
aioredis.exceptions.ResponseError: wrong number of arguments for 'del' command
@wiseaidev wiseaidev changed the title delete will throw an exception if called twice on the same record. delete will throw an exception if invoked on a non existing record. Aug 18, 2022
@dvora-h
Copy link
Contributor

dvora-h commented Sep 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants