Skip to content
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

get doesn't work for imported redis_om hashmodel #494

Open
plsholdmybeer opened this issue Mar 18, 2023 · 1 comment
Open

get doesn't work for imported redis_om hashmodel #494

plsholdmybeer opened this issue Mar 18, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@plsholdmybeer
Copy link

plsholdmybeer commented Mar 18, 2023

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

@AdityaPunetha
Copy link

AdityaPunetha commented Apr 12, 2023

Same issue
Link

@chayim chayim added the bug Something isn't working label Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants