Skip to content

Commit 2be329f

Browse files
committed
get primary key field using the key method
Signed-off-by: wiseaidev <[email protected]>
1 parent 6e5557a commit 2be329f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

aredis_om/model/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ def __init__(__pydantic_self__, **data: Any) -> None:
11101110

11111111
def __lt__(self, other):
11121112
"""Default sort: compare primary key of models."""
1113-
return self.pk < other.pk
1113+
return self.key() < other.key()
11141114

11151115
def key(self):
11161116
"""Return the Redis key for this model."""
@@ -1149,7 +1149,7 @@ async def expire(
11491149
db = self._get_db(pipeline)
11501150

11511151
# TODO: Wrap any Redis response errors in a custom exception?
1152-
await db.expire(self.make_primary_key(self.pk), num_seconds)
1152+
await db.expire(self.make_primary_key(self.key()), num_seconds)
11531153

11541154
@validator("pk", always=True, allow_reuse=True)
11551155
def validate_pk(cls, v):
@@ -1274,7 +1274,7 @@ async def delete_many(
12741274
db = cls._get_db(pipeline)
12751275

12761276
for chunk in ichunked(models, 100):
1277-
pks = [cls.make_primary_key(model.pk) for model in chunk]
1277+
pks = [cls.make_primary_key(model.key()) for model in chunk]
12781278
await cls._delete(db, *pks)
12791279

12801280
return len(models)

tests/test_hash_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ async def test_delete_many(m):
618618
result = await m.Member.delete_many(members)
619619
assert result == 2
620620
with pytest.raises(NotFoundError):
621-
await m.Member.get(pk=member1.id)
621+
await m.Member.get(pk=member1.key())
622622

623623

624624
@py_test_mark_asyncio

0 commit comments

Comments
 (0)