redis / redis-om-python

Object mapping, and more, for Redis and Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent .pk behaviour

kantholtz opened this issue · comments

Hi, I've tripped over how the .pk property works for Models.

Consider this:

>>> from redis_om import HashModel, Field, Migrator
... 
... class A(HashModel):
...     x: int
... 
... class B(HashModel):
...     x: int = Field(primary_key=True)
... 
... Migrator().run()
... 
... a = A(x=3)
... b = B(x=3)
>>> a.pk
'01H9MZDZRHHDAQZY28F7ETGFHB'
>>> b.pk
<redis_om.model.model.ExpressionProxy object at 0x7f635ceb1d50>
  1. What is an ExpressionProxy object?
  2. Why is b.pk not 3?

In my opinion, using any HashModel or JsonModel should not require knowledge about whether their pk is auto-generated or explicitly declared.

I hope this was not described anywhere in the docs, but I did not find anything.