mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
fix: fix json.arrappend not allowing passing JSON objects (#1867)
Signed-off-by: Uku Loskit <ukuloskit@gmail.com>
This commit is contained in:
parent
82050248b0
commit
7a5fe1adc1
2 changed files with 28 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue