redis-om-python icon indicating copy to clipboard operation
redis-om-python copied to clipboard

get doesn't work for imported redis_om hashmodel

Open plsholdmybeer opened this issue 2 years ago • 1 comments

TLDR:

running with commented block, prints empty. uncommenting, works fine, I might be missing something but it shouldn't do that. (Product is defined in 'product' module, not here in other.py, but in order for fetching data to work, I must also define the same class here)

from redis_om import HashModel
from product import redis, Product

# class Product(HashModel):
#     class Meta:
#         database = redis
        
print(list(Product.all_pks()))

code is isolated, I'm going insane, running product.py results in 2 products being printed. using that product.py as a module in other.py results in Product.all_pks returning empty, Product.get raising Exception for data not found. What am I doing wrong?

running it from vscode inside venv, happens on both regular and debug run. I can see the connection from other.py but I don't know what or where to dig deeper to figure out what's wrong.

product.py

from redis_om import get_redis_connection, HashModel

redis = get_redis_connection(
    host="-",
    port=12262,
    password="-",
    decode_responses=True
)

class Product(HashModel):
    class Meta:
        database = redis

print(list(Product.all_pks()))
# ran as main prints 2 products

other.py

from redis_om import get_redis_connection, HashModel
import product

# ran as main without line below it runs the other scripts but prints []
# print(list(product.Product.all_pks())) # this also prints []

more testing, other.py, using redis from main but defining the Product again

from redis_om import HashModel
from product import redis, Product

class Product(HashModel):
    class Meta:
        database = redis
        
import product # just trying, prints []
print(list(Product.all_pks())) # prints 2 products

it's not the nested class,

print(Product._meta.database)

returns the same with and without the commented part

plsholdmybeer avatar Mar 18 '23 02:03 plsholdmybeer

Same issue Link

AdityaPunetha avatar Apr 12 '23 11:04 AdityaPunetha