Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dag.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,11 @@ void DAG_ReplyAndUnblock(RedisAI_OnFinishCtx ctx, void *private_data) {
int RedisAI_ProcessDagRunCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc,
int dagMode) {

int flags = RedisModule_GetContextFlags(ctx);
bool blocking_not_allowed = (flags & (REDISMODULE_CTX_FLAGS_MULTI | REDISMODULE_CTX_FLAGS_LUA));
if (blocking_not_allowed)
return RedisModule_ReplyWithError(
ctx, "ERR Cannot run RedisAI command within a transaction or a LUA script");
RedisAI_RunInfo *rinfo = NULL;
if (RAI_InitRunInfo(&rinfo) == REDISMODULE_ERR) {
RedisModule_ReplyWithError(
Expand Down
22 changes: 21 additions & 1 deletion tests/flow/tests_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,24 @@ def test_info_modules(env):
env.assertEqual( 'ai_self_used_cpu_user' in ret, True )
env.assertEqual( 'ai_children_used_cpu_sys' in ret, True )
env.assertEqual( 'ai_children_used_cpu_user' in ret, True )
env.assertEqual( 'ai_queue_CPU_bthread_#1_used_cpu_total' in ret, True )
env.assertEqual( 'ai_queue_CPU_bthread_#1_used_cpu_total' in ret, True )

def test_lua_multi(env):
con = env.getConnection()
ret = con.execute_command('MULTI')
env.assertEqual(ret, b'OK')
ret = con.execute_command('AI.MODELRUN', "no_model{1}", "INPUTS", "no_input{1}", "OUTPUTS", "no_output{1}")
env.assertEqual(ret, b'QUEUED')
try:
ret = con.execute_command('EXEC')
except Exception as e:
exception = e
env.assertEqual(type(exception), redis.exceptions.ResponseError)
env.assertEqual("ERR Cannot run RedisAI command within a transaction or a LUA script", exception.__str__())
try:
ret = con.execute_command('EVAL', "return redis.pcall('AI.MODELRUN', 'no_model{1}', 'INPUTS', 'NO_INPUT{1}',"
" 'OUTPUTS', 'NO_OUTPUT{1}')", 0)
except Exception as e:
exception = e
env.assertEqual(type(exception), redis.exceptions.ResponseError)
env.assertEqual("Cannot run RedisAI command within a transaction or a LUA script", exception.__str__())