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
'NoneType' object is not subscriptable #532
Comments
|
I'm having the same issue using
Code: import redis_om
import datetime
from typing import Optional
class Server(redis_om.HashModel):
hostname: str
ip: Optional[str]
port: int
created: datetime.datetime
if __name__ == '__main__':
print(Server.find(Server.hostname == 'xx.xx.xx.xx')) I'm using:
I don't think the code has a problem, because I get the exam same result by using the code given in the docs. |
Hi, Any solution over this, i'm facing the same issue. |
@Praj-17 I changed to Redis Stack Server. I think the problem was that I was missing the Redisearch module. |
I face this problem too, and I found that the problem is that the Redis Server we use is Start a - docker run -p 6379:6379 -d redis:lastest
+ docker run -p 6379:6379 -d redis/redis-stack:lastest The code I use to verify this problem is as follow: from redis_om import get_redis_connection
from redis_om import JsonModel , HashModel , Migrator , Field
from typing import Optional
REDIS_URL = "redis://localhost:6379"
redis = get_redis_connection(url=REDIS_URL)
class UserJsonCache( JsonModel ):
id: int = Field(index=True)
name : str = Field(index=True)
email: str = Field(index=True)
avatar:Optional[str] = Field(index=False)
class Meta:
database = redis
class UserHashCache( HashModel ):
id: int = Field(index=True)
name : str = Field(index=True)
email: str = Field(index=True)
avatar:Optional[str] = Field(index=False)
class Meta:
database = redis
Migrator().run()
def test_create_user_json():
new_user = UserJsonCache(id=1,name="json_user",email="json_user@email.com",avatar="image_url")
new_user.save()
pk = new_user.pk
assert UserJsonCache.get(pk) == new_user
def test_find_user_json():
user_be_found = UserJsonCache(id=1,name="json_user",email="json_user@email.com",avatar="image_url")
res = UserJsonCache.find( UserJsonCache.id==1 ).first()
assert res.id == user_be_found.id
assert res.name == user_be_found.name
assert res.email == user_be_found.email
assert res.avatar == user_be_found.avatar
'''
We can't use assert `res == user_be_found` because `pk` is different
'''
def test_create_user_hash():
new_user = UserHashCache(id=2,name="hash_user",email="hash_user@email.com",avatar="image_url")
new_user.save()
pk = new_user.pk
assert UserHashCache.get(pk) == new_user
def test_find_user_hash():
user_be_found = UserHashCache(id=2,name="hash_user",email="hash_user@email.com",avatar="image_url")
res = UserHashCache.find( UserHashCache.id==2 ).first()
assert res.id == user_be_found.id
assert res.name == user_be_found.name
assert res.email == user_be_found.email
assert res.avatar == user_be_found.avatar Run well no matter using |
@jason810496 |
Going to close to tidy up (pretty clearly a redis/module version issues) |
When i create a
Task
(Even did not call anysave()
stuff). It crashes. I guess something is missingThe text was updated successfully, but these errors were encountered: