Fix crash when trying to delete non-existent record (#372)
This commit is contained in:
parent
285f7c90ee
commit
e9529e35be
2 changed files with 26 additions and 1 deletions
|
@ -32,6 +32,7 @@ from pydantic.main import ModelMetaclass, validate_model
|
|||
from pydantic.typing import NoArgAnyCallable
|
||||
from pydantic.utils import Representation
|
||||
from redis.commands.json.path import Path
|
||||
from redis.exceptions import ResponseError
|
||||
from typing_extensions import Protocol, get_args, get_origin
|
||||
from ulid import ULID
|
||||
|
||||
|
@ -799,7 +800,10 @@ class FindQuery:
|
|||
async def delete(self):
|
||||
"""Delete all matching records in this query."""
|
||||
# TODO: Better response type, error detection
|
||||
return await self.model.db().delete(*[m.key() for m in await self.all()])
|
||||
try:
|
||||
return await self.model.db().delete(*[m.key() for m in await self.all()])
|
||||
except ResponseError:
|
||||
return 0
|
||||
|
||||
async def __aiter__(self):
|
||||
if self._model_cache:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue