Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Transaction data decoding is incorrect #657

Closed
dmvass opened this issue Oct 31, 2019 · 2 comments · Fixed by #658
Closed

Transaction data decoding is incorrect #657

dmvass opened this issue Oct 31, 2019 · 2 comments · Fixed by #658

Comments

@dmvass
Copy link
Contributor

dmvass commented Oct 31, 2019

Transaction data always decoded two times if connection encoding was defined:

Test case:

@pytest.mark.run_loop
async def test_global_encoding(redis, create_redis, server, loop):
    redis = await create_redis(
        server.tcp_address,
        loop=loop, encoding='utf-8')
    res = await redis.set('key', 'value')
    assert res is True
    res = await redis.hmset(
        'hash-key', 'foo', 'val1', 'bar', 'val2')
    assert res is True

    tr = redis.multi_exec()
    fut1 = tr.get('key')
    fut2 = tr.get('key', encoding='utf-8')
    fut3 = tr.get('key', encoding=None)
    fut4 = tr.hgetall('hash-key', encoding='utf-8')
    await tr.execute()
    res = await fut1
    assert res == 'value'
    res = await fut2
    assert res == 'value'
    res = await fut3
    assert res == b'value'
    res = await fut4
    assert res == {'foo': 'val1', 'bar': 'val2'}

Tracing for util.decode

decode(b'PONG', utf-8)
decode(b'OK', utf-8)
decode(b'OK', utf-8)
decode(b'OK', utf-8)
decode(b'QUEUED', utf-8)
decode(b'QUEUED', utf-8)
decode(b'QUEUED', utf-8)
decode([b'value', b'value', b'value', [b'foo', b'val1', b'bar', b'val2']], utf-8)
decode(b'value', utf-8)
decode(b'value', utf-8)
decode(b'value', utf-8)
decode([b'foo', b'val1', b'bar', b'val2'], utf-8)
decode(b'foo', utf-8)
decode(b'val1', utf-8)
decode(b'bar', utf-8)
decode(b'val2', utf-8)
decode(value, utf-8)
decode(value, utf-8)
decode(['foo', 'val1', 'bar', 'val2'], utf-8)
decode(foo, utf-8)
decode(val1, utf-8)
decode(bar, utf-8)
decode(val2, utf-8)

You can see that multi-exec response [b'value', b'value', b'value', [b'foo', b'val1', b'bar', b'val2']] was decoded twice. In this case decoding in RedisConnection._end_transaction is not make sense because we have already decoded it in the RedisConnection._process_data.

@dmvass
Copy link
Contributor Author

dmvass commented Nov 27, 2019

@popravich friendly ping

@popravich
Copy link
Contributor

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants