fix: fix json.arrappend not allowing passing JSON objects (#1867)

Signed-off-by: Uku Loskit <ukuloskit@gmail.com>
This commit is contained in:
Uku Loskit 2023-09-16 12:27:20 +03:00 committed by GitHub
parent 82050248b0
commit 7a5fe1adc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 7 deletions

View file

@ -1375,12 +1375,6 @@ void JsonFamily::ArrAppend(CmdArgList args, ConnectionContext* cntx) {
(*cntx)->SendError(kSyntaxErr);
return;
}
if (converted_val->is_object()) {
(*cntx)->SendError(kWrongTypeErr);
return;
}
append_values.emplace_back(converted_val);
}

View file

@ -2,7 +2,7 @@ import pytest
import redis
from redis import asyncio as aioredis
from .utility import *
from json import JSONDecoder, JSONEncoder
from json import JSONDecoder, JSONEncoder, dumps
jane = {"name": "Jane", "Age": 33, "Location": "Chawton"}
@ -84,3 +84,30 @@ async def test_update_value(async_client: aioredis.Redis):
except redis.exceptions.ResponseError as e:
assert e.args[0] == "WRONGTYPE Operation against a key holding the wrong kind of value"
assert await async_client.type(key_name) == "string"
@pytest.mark.parametrize(
"description,expected_value,expected_type",
(
("array", "[]", "array"),
("string", dumps("dragonfly"), "string"),
("number", dumps(3.50), "number"),
("object", dumps({"dragon": "fly"}, separators=(",", ":")), "object"),
("boolean true", "true", "boolean"),
("boolean false", "false", "boolean"),
),
)
@pytest.mark.asyncio
async def test_arrappend(async_client: aioredis.Redis, description, expected_value, expected_type):
key_name = "test-json-key"
await async_client.execute_command("json.set", key_name, "$", "[]")
await async_client.execute_command("json.arrappend", key_name, "$", expected_value)
# make sure the value is as expected
first_element = await async_client.execute_command("json.get", key_name, "$[0]")
assert first_element == "[{}]".format(expected_value)
# make sure the type is as expected
actual_type = await async_client.execute_command("json.type", key_name, "$[0]")
assert actual_type[0] == expected_type