diff --git a/aredis_om/model/model.py b/aredis_om/model/model.py index 0d9ea05..0c2ef60 100644 --- a/aredis_om/model/model.py +++ b/aredis_om/model/model.py @@ -1114,8 +1114,10 @@ class RedisModel(BaseModel, abc.ABC, metaclass=ModelMeta): pk = getattr(self, self._meta.primary_key.field.name) return self.make_primary_key(pk) - async def delete(self): - return await self.db().delete(self.key()) + @classmethod + async def delete(cls, pk: Any) -> int: + """Delete data at this key.""" + return await cls.db().delete(cls.make_primary_key(pk)) @classmethod async def get(cls, pk: Any) -> "RedisModel": @@ -1335,10 +1337,6 @@ class HashModel(RedisModel, abc.ABC): result = cls.parse_obj(document) return result - @classmethod - async def delete(cls, pk: Any) -> int: - return await cls.db().delete(cls.make_primary_key(pk)) - @classmethod @no_type_check def _get_value(cls, *args, **kwargs) -> Any: @@ -1507,10 +1505,6 @@ class JsonModel(RedisModel, abc.ABC): raise NotFoundError return cls.parse_raw(document) - @classmethod - async def delete(cls, pk: Any) -> int: - return await cls.db().delete(cls.make_primary_key(pk)) - @classmethod def redisearch_schema(cls): key_prefix = cls.make_key(cls._meta.primary_key_pattern.format(pk="")) diff --git a/tests/test_hash_model.py b/tests/test_hash_model.py index a48999f..133e43a 100644 --- a/tests/test_hash_model.py +++ b/tests/test_hash_model.py @@ -374,6 +374,7 @@ async def test_saves_model_and_creates_pk(m): member2 = await m.Member.get(member.pk) assert member2 == member + @pytest.mark.asyncio async def test_delete(m): member = m.Member( @@ -382,7 +383,7 @@ async def test_delete(m): email="s@example.com", join_date=today, age=97, - bio="This is a test use to be deleted.", + bio="This is a test user to be deleted.", ) await member.save() diff --git a/tests/test_json_model.py b/tests/test_json_model.py index ce240e0..d920a40 100644 --- a/tests/test_json_model.py +++ b/tests/test_json_model.py @@ -186,6 +186,7 @@ async def test_saves_model_and_creates_pk(address, m, redis): assert member2 == member assert member2.address == address + @pytest.mark.asyncio async def test_delete(address, m, redis): member = m.Member(