Skip to content

fixed invalid model get reponse #558

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jan 12, 2021
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
3 changes: 1 addition & 2 deletions src/command_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ static int _ModelRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **a
size_t argpos = 1;
RedisModuleKey *modelKey;
const int status =
RAI_GetModelFromKeyspace(ctx, argv[argpos], &modelKey, model, REDISMODULE_READ);
RAI_GetModelFromKeyspace(ctx, argv[argpos], &modelKey, model, REDISMODULE_READ, error);
if (status == REDISMODULE_ERR) {
RAI_SetError(error, RAI_EMODELRUN, "ERR Model not found");
return REDISMODULE_ERR;
}
RAI_HoldString(NULL, argv[argpos]);
Expand Down
7 changes: 4 additions & 3 deletions src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@
#include "util/string_utils.h"
#include <pthread.h>
#include "DAG/dag.h"
#include "err.h"

/* Return REDISMODULE_ERR if there was an error getting the Model.
* Return REDISMODULE_OK if the model value stored at key was correctly
* returned and available at *model variable. */
int RAI_GetModelFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RedisModuleKey **key,
RAI_Model **model, int mode) {
RAI_Model **model, int mode, RAI_Error *error) {
*key = RedisModule_OpenKey(ctx, keyName, mode);
if (RedisModule_KeyType(*key) == REDISMODULE_KEYTYPE_EMPTY) {
RedisModule_CloseKey(*key);
RedisModule_ReplyWithError(ctx, "ERR model key is empty");
RAI_SetError(error, REDISMODULE_KEYTYPE_EMPTY, "ERR model key is empty");
return REDISMODULE_ERR;
}
if (RedisModule_ModuleTypeGetType(*key) != RedisAI_ModelType) {
RedisModule_CloseKey(*key);
RedisModule_ReplyWithError(ctx, REDISMODULE_ERRORMSG_WRONGTYPE);
RAI_SetError(error, REDISMODULE_ERR, REDISMODULE_ERRORMSG_WRONGTYPE);
return REDISMODULE_ERR;
}
*model = RedisModule_ModuleTypeGetValue(*key);
Expand Down
3 changes: 2 additions & 1 deletion src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ int RAI_ModelSerialize(RAI_Model *model, char **buffer, size_t *len, RAI_Error *
* a Redis key with the requested access mode
* @param model destination model structure
* @param mode key access mode
* @param error contains the error in case of problem with retrival
* @return REDISMODULE_OK if the model value stored at key was correctly
* returned and available at *model variable, or REDISMODULE_ERR if there was
* an error getting the Model
*/
int RAI_GetModelFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RedisModuleKey **key,
RAI_Model **model, int mode);
RAI_Model **model, int mode, RAI_Error *error);

/**
* When a module command is called in order to obtain the position of
Expand Down
13 changes: 9 additions & 4 deletions src/redisai.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,11 @@ int RedisAI_ModelGet_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,

RAI_Model *mto;
RedisModuleKey *key;
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto, REDISMODULE_READ);
RAI_Error err = {0};
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto, REDISMODULE_READ, &err);
if (status == REDISMODULE_ERR) {
RedisModule_ReplyWithError(ctx, err.detail);
RAI_ClearError(&err);
return REDISMODULE_ERR;
}

Expand All @@ -434,7 +437,6 @@ int RedisAI_ModelGet_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
return RedisModule_ReplyWithError(ctx, "ERR no META or BLOB specified");
}

RAI_Error err = {0};
char *buffer = NULL;
size_t len = 0;

Expand Down Expand Up @@ -512,11 +514,14 @@ int RedisAI_ModelDel_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
if (argc != 2)
return RedisModule_WrongArity(ctx);

RAI_Error err = {0};
RAI_Model *mto;
RedisModuleKey *key;
const int status =
RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto, REDISMODULE_READ | REDISMODULE_WRITE);
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto,
REDISMODULE_READ | REDISMODULE_WRITE, &err);
if (status == REDISMODULE_ERR) {
RedisModule_ReplyWithError(ctx, err.detail);
RAI_ClearError(&err);
return REDISMODULE_ERR;
}

Expand Down