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

Model.find() is giving error #581

Closed
muslih-DIY opened this issue Dec 29, 2023 · 4 comments
Closed

Model.find() is giving error #581

muslih-DIY opened this issue Dec 29, 2023 · 4 comments

Comments

@muslih-DIY
Copy link

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
Copy link
Author

muslih-DIY commented Dec 29, 2023

this part of the program is causing the issue

cmd_info = await conn.execute_command("command", "info", cmd)

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 added a commit to muslih-DIY/redis-om-python that referenced this issue Dec 29, 2023
muslih-DIY added a commit to muslih-DIY/redis-om-python that referenced this issue Dec 29, 2023
@muslih-DIY
Copy link
Author

muslih-DIY commented Dec 29, 2023

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

this may also solve #532

muslih-DIY added a commit to muslih-DIY/redis-om-python that referenced this issue Dec 29, 2023
@slorello89
Copy link
Member

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
Copy link
Member

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

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

No branches or pull requests

2 participants