redis / redis-py

Redis Python client
MIT License
12.69k stars 2.53k forks source link

NameError: name 'hiredis' is not defined due to hiredis version being lower than 3 #3393

Closed helissonomc closed 1 month ago

helissonomc commented 1 month ago

Version: 5.1.0

Platform: Python 3.12 / ubuntu 22.04

Description: I started to get the error output.append(hiredis.pack_command(args)) NameError: name 'hiredis' is not defined

I Believe the reason for this issue is because of the code inside redis/utils.py

try:
    import hiredis  # noqa

    # Only support Hiredis >= 3.0:
    HIREDIS_AVAILABLE = int(hiredis.__version__.split(".")[0]) >= 3
    HIREDIS_PACK_AVAILABLE = hasattr(hiredis, "pack_command")
except ImportError:
    HIREDIS_AVAILABLE = False
    HIREDIS_PACK_AVAILABLE = False

If the hiredis version is lower than 3 (which mine is) the HIREDIS_AVAILABLE is going to be false, therefore it will keep giving error inside the redis/connection.py file, because the import hiredis will not be executed, but the code still relies on this import.

I believe there should be a better error handling here warning people about this breaking change.

Endzel commented 1 month ago

Upvoting this, disrupting our builds since yesterday evening.

helissonomc commented 1 month ago

@Endzel https://github.com/redis/redis-py/issues/3392 check this out, they will fix the bug