redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.11k stars 110 forks source link

Model.find() is giving error #581

Closed muslih-DIY closed 5 months ago

muslih-DIY commented 9 months ago

class HashModelExtended(HashModel, abc.ABC):

    __primary_key_pattern__ = "{pk}"

    def __init__(self, **data: Any) -> None:
        pk = self.__primary_key_pattern__.format(**data)
        super().__init__(**data, pk=pk)

    @classmethod
    def pk_generate(cls, **data):
        return cls.__primary_key_pattern__.format(**data)

class AgentDevice(HashModelExtended):
    username: str
    callcenter: int = Field(index=True)
    endpoint: int = Field(index=True)
    agent_id: int = Field(index=True)
    ipaddress: Optional[str]
    status: Optional[str]

    __primary_key_pattern__ = "{callcenter}:{endpoint}"

    class Meta:
        global_key_prefix = "agent"
        model_key_prefix = "device"
        primary_key_pattern = "{pk}"
        index_name = "agentdevice-index"

here is the program i was trying after declaring the model


print(AgentDevice.find(AgentDevice.callcenter == 1))
  File "/project/venv/lib/python3.11/site-packages/redis_om/checks.py", line 25, in has_redisearch
    if has_redis_json(conn):
       ^^^^^^^^^^^^^^^^^^^^
  File "/project/venv/lib/python3.11/site-packages/redis_om/checks.py", line 17, in has_redis_json
    command_exists = check_for_command(conn, "json.set")
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/project/venv/lib/python3.11/site-packages/redis_om/checks.py", line 9, in check_for_command
    cmd_info = conn.execute_command("command", "info", cmd)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/project/venv/lib/python3.11/site-packages/redis/client.py", line 1269, in execute_command
    return conn.retry.call_with_retry(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/project/venv/lib/python3.11/site-packages/redis/retry.py", line 46, in call_with_retry
    return do()
           ^^^^
  File "/project/venv/lib/python3.11/site-packages/redis/client.py", line 1270, in <lambda>
    lambda: self._send_command_parse_response(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/project/venv/lib/python3.11/site-packages/redis/client.py", line 1246, in _send_command_parse_response
    return self.parse_response(conn, command_name, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/project/venv/lib/python3.11/site-packages/redis/client.py", line 1296, in parse_response
    return self.response_callbacks[command_name](response, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/project/venv/lib/python3.11/site-packages/redis/client.py", line 560, in parse_command
    cmd_name = str_if_bytes(command[0])
                            ~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable
muslih-DIY commented 9 months ago

this part of the program is causing the issue https://github.com/redis/redis-om-python/blob/1213ca7373ba4f1347a5298e7f6f63cb09949ad2/aredis_om/checks.py#L9

i was working with redis_om not aredis_om

from functools import lru_cache
from typing import List

from redis_om.connections import get_redis_connection

@lru_cache(maxsize=None)
def check_for_command(conn, cmd):
    cmd_info = conn.execute_command("command","info" ,cmd)
    return None not in cmd_info

@lru_cache(maxsize=None)
def has_redis_json(conn=None):
    if conn is None:
        conn = get_redis_connection()
    command_exists = check_for_command(conn, "json.set")
    return command_exists

@lru_cache(maxsize=None)
def has_redisearch(conn=None):
    if conn is None:
        conn = get_redis_connection()
    if has_redis_json(conn):
        return True
    command_exists = check_for_command(conn, "ft.search")
    return command_exists
muslih-DIY commented 9 months ago

@uglide if it is works, please create and merge this issue

this may also solve #532

slorello89 commented 6 months ago

This sounds like a Redis Versioning / ACL issue - are you using a version of Redis with COMMAND INFO and one where you've given the client permission to use the COMMAND INFO command?

slorello89 commented 5 months ago

Going to close this issue to tidy up (think it's an ACL issue) if the issue persists please feel free to reopen.