Skip to content

Commit bad888c

Browse files
committed
Return an error when trying to run MODELRUN/SCRIPTRUN/DAGRUN through multi or lua (until we support non blocking executions)
1 parent 78c77cf commit bad888c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/dag.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,11 @@ void DAG_ReplyAndUnblock(RedisAI_OnFinishCtx ctx, void *private_data) {
13121312
int RedisAI_ProcessDagRunCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc,
13131313
int dagMode) {
13141314

1315+
int flags = RedisModule_GetContextFlags(ctx);
1316+
bool blocking_not_allowed = (flags & (REDISMODULE_CTX_FLAGS_MULTI | REDISMODULE_CTX_FLAGS_LUA));
1317+
if (blocking_not_allowed)
1318+
return RedisModule_ReplyWithError(
1319+
ctx, "ERR Cannot run RedisAI command within a transaction or a LUA script");
13151320
RedisAI_RunInfo *rinfo = NULL;
13161321
if (RAI_InitRunInfo(&rinfo) == REDISMODULE_ERR) {
13171322
RedisModule_ReplyWithError(

tests/flow/tests_common.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,24 @@ def test_info_modules(env):
301301
env.assertEqual( 'ai_self_used_cpu_user' in ret, True )
302302
env.assertEqual( 'ai_children_used_cpu_sys' in ret, True )
303303
env.assertEqual( 'ai_children_used_cpu_user' in ret, True )
304-
env.assertEqual( 'ai_queue_CPU_bthread_#1_used_cpu_total' in ret, True )
304+
env.assertEqual( 'ai_queue_CPU_bthread_#1_used_cpu_total' in ret, True )
305+
306+
def test_lua_multi(env):
307+
con = env.getConnection()
308+
ret = con.execute_command('MULTI')
309+
env.assertEqual(ret, b'OK')
310+
ret = con.execute_command('AI.MODELRUN', "no_model", "INPUTS", "no_input", "OUTPUTS", "no_output")
311+
env.assertEqual(ret, b'QUEUED')
312+
try:
313+
ret = con.execute_command('EXEC')
314+
except Exception as e:
315+
exception = e
316+
env.assertEqual(type(exception), redis.exceptions.ResponseError)
317+
env.assertEqual("ERR Cannot run RedisAI command within a transaction or a LUA script", exception.__str__())
318+
try:
319+
ret = con.execute_command('EVAL', "return redis.pcall('AI.MODELRUN', 'no_model', 'INPUTS', 'NO_INPUT',"
320+
" 'OUTPUTS', 'NO_OUTPUT')", 0)
321+
except Exception as e:
322+
exception = e
323+
env.assertEqual(type(exception), redis.exceptions.ResponseError)
324+
env.assertEqual("Cannot run RedisAI command within a transaction or a LUA script", exception.__str__())

0 commit comments

Comments
 (0)