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
To address the issues with the RedisCache in Langflow version 1.1.1, you can make the following changes:
Fixing the RuntimeError in is_connected:
Avoid using asyncio.run() within an already running event loop. Instead, check if the event loop is running and use create_task or run_until_complete accordingly. Here's a modified version of the is_connected method:
defis_connected(self) ->bool:
"""Check if the Redis client is connected."""importredistry:
loop=asyncio.get_event_loop()
ifloop.is_running():
# If the loop is already running, use create_tasktask=loop.create_task(self._client.ping())
loop.run_until_complete(task)
else:
asyncio.run(self._client.ping())
exceptredis.exceptions.ConnectionError:
logger.exception("RedisCache could not connect to the Redis server")
returnFalsereturnTrue
Handling Serialization Issues:
Ensure that only picklable objects are cached. Add a check before attempting to pickle the object in the set method:
@overrideasyncdefset(self, key, value, lock=None) ->None:
try:
# Check if the value can be pickledpickle.dumps(value)
ifpickled:=pickle.dumps(value):
result=awaitself._client.setex(str(key), self.expiration_time, pickled)
ifnotresult:
msg="RedisCache could not set the value."raiseValueError(msg)
except (TypeError, pickle.PicklingError) asexc:
msg="RedisCache only accepts values that can be pickled."raiseTypeError(msg) fromexc
These changes should help resolve the RuntimeError and serialization issues you are encountering with the RedisCache on MacOS [1].
Bug Description
I've encountered two bugs while using
RedisCache
:The
is_connected
method:langflow/src/backend/base/langflow/services/cache/service.py
Lines 222 to 227 in a97c29f
is called within an asynchronous method:
langflow/src/backend/base/langflow/main.py
Line 105 in a97c29f
When using
asyncio.run
, it raises the error:RuntimeError: asyncio.run() cannot be called from a running event loop.
Serialization error occurs for graphs and many outputs that are not of Message and Data component types, raising
TypeError
orPicklingError
:langflow/src/backend/base/langflow/services/cache/service.py
Lines 241 to 250 in a97c29f
Reproduction
Set Environment Variable:
LANGFLOW_CACHE_TYPE
toredis
.Start Application:
asyncio.run
, specifically:Modify Code:
is_connected
method call.Expected behavior
The
RedisCache
should initialize without raising errors.The
RedisCache
should accept values without raising serialization errors, ensuring compatibility with various output types.Who can help?
@italojohnny
Operating System
MacOS
Langflow Version
1.1.1
Python Version
None
Screenshot
No response
Flow File
No response
The text was updated successfully, but these errors were encountered: