You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'''test_redis_storage.py'''importpytestfromosimportgetenv, environfrompytest_docker_toolsimportcontainerredis=container(
name="test-redis",
image="redis/redis-stack:7.2.0-v13",
ports={6379: 16379, 8001: 18001},
)
environ["REDIS_OM_URL"] =f"redis://localhost:16379/0"fromgreenflow.redis_storageimportExperiment, ExperimentMetadata, ExpStorage@pytest.fixturedefstorage(redis):
fromredis_omimportget_redis_connection"""Fixture for ExpStorage instance"""# Migrator().run()redis=get_redis_connection(url=getenv("REDIS_OM_URL"))
load_gin(exp_name="test-platform", test=True)
storage=ExpStorage()
yieldstorage# Cleanup: Delete all keys after each testredis.flushdb()
classTestExpStorage:
deftest_find_experiments_by_name(self, storage):
fromredis_omimportMigrator"""Test finding experiments by name"""# Create multiple experimentsexp1=Experiment(exp_name="test1")
exp1.save()
exp2=Experiment(exp_name="test2")
exp2.save()
Migrator().run()
results=Experiment.find(Experiment.exp_name=="test1").all()
assertlen(results) ==1
When the test runs (and fails), I can see that the redis instance does have correct keys inserted. However, the assertion always fails as an empty list is returned.
I believe this is because ExperimentMetadata is a JsonModel. In fact, I tried changing it to a Dict[str, Any] and it still doesn't work and returns an empty list
The text was updated successfully, but these errors were encountered:
I also ran into this issue, I started with an empty db, created model instances with .save() and then, ran find().all() which returned nothing, despite the fact that the instance was saved.
I investigated this for quite a bit and ultimately narrowed down the cause to an optional Dict field that looked like this:
class MyModel(JsonModel):
# Other fields
this = Optional[Dict[str, int]] = Field(default_factory=dict)
# this field caused indexing to fail
this field which is of type Optional[Dict[str, int]], caused indexing to fail for the whole object (including the other fields/values). When I called my_model_instance.save(), I expected the instance to be indexed but it was not indexed, but there was no error/warning during model.save() that would make me aware that indexing failed. I only realized the issue after realizing that MyModel.find().all() returned nothing and later checking that indexes were not being populated (using FT.INFO)
Once I removed this field, the automatic-indexing on calling .save() worked and find().all() started working again as expected.
Minimal example:
I believe this is because ExperimentMetadata is a
JsonModel
. In fact, I tried changing it to a Dict[str, Any] and it still doesn't work and returns an empty listThe text was updated successfully, but these errors were encountered: