Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Change in redis-py v5.0.8 causes strange behavior in fakeredis-py #316

Closed
x0ul opened this issue Jul 31, 2024 · 3 comments
Closed

Change in redis-py v5.0.8 causes strange behavior in fakeredis-py #316

x0ul opened this issue Jul 31, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@x0ul
Copy link

x0ul commented Jul 31, 2024

Describe the bug

  • Using python 3.12.4
  • Bug appears in fakeredis-py v2.23.4 when redis-py is v5.0.8 (offending commit found via bisect redis/redis-py@e7ef54a)
  • Bug does not occur running the same test with real redis server (7.2.5) and redis-py (v5.0.8)

fakeredis-py returns unexpected values for get that appear to be left over results from the previous command

To Reproduce
Steps to reproduce the behavior:

Run the following test case with pytest

    @pytest.mark.asyncio
    async def test_cause_fakeredis_bug():
        redis = fakeredis.FakeAsyncRedis()
    
        async def worker_task():
            await redis.rpush("list1", "list1_val")
            assert await redis.blpop("list2") == (b"list2", b"list2_val")
            await redis.set("foo", "bar")
    
        async with asyncio.TaskGroup() as tg:
            tg.create_task(worker_task())
            assert await redis.blpop("list1") == (b"list1", b"list1_val")
            await redis.rpush("list2", "list2_val")
    
        # await redis.get("foo")  # uncomment to make test pass
>       assert await redis.get("foo") == b"bar"
E       AssertionError: assert b'OK' == b'bar'
E         
E         At index 0 diff: b'O' != b'b'
E         
E         Full diff:
E         - b'bar'
E         + b'OK'

Expected behavior
Test passes. This test passes with redis-py v5.0.7.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Linux 6.10.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 27 Jul 2024 16:49:55 +0000 x86_64 GNU/Linux
  • python version: 3.12.4
  • redis-py version: v2.23.4
  • full requirements.txt?

Additional context
Doing another get (see commented-out line in test case above) seems to re-sync the connection and cause the test to pass.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@cunla
Copy link
Owner

cunla commented Aug 3, 2024

I am surprised this is the first time this was mentioned. Anyway, should be fixed.

@cunla cunla closed this as completed Aug 3, 2024
@x0ul
Copy link
Author

x0ul commented Aug 3, 2024

Thanks so much for the quick fix, I seriously appreciate what this library has helped me do. Was removing this call to put_response the main change?

@cunla
Copy link
Owner

cunla commented Aug 3, 2024

yes, it is writing the response a few lines afterwards in the finally section

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants