Skip to content

run GraphCommands.explain raise TypeError #1848

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

Closed
ChandlerBent opened this issue Jan 4, 2022 · 2 comments · Fixed by #1901
Closed

run GraphCommands.explain raise TypeError #1848

ChandlerBent opened this issue Jan 4, 2022 · 2 comments · Fixed by #1901

Comments

@ChandlerBent
Copy link

ChandlerBent commented Jan 4, 2022

Version: 4.1.0

Python Version: 3.8

Platform: MacOS 12.0.1

Description: I'm using redisgraph:2.8.7 with redis-py. I met a error when I run explain. Error:

graph.explain('match (n:person) where n.name = "ken" return n')

raise exception

File "/lib/python3.8/site-packages/redis/commands/graph/commands.py", line 140, in explain
    return "\n".join(plan)
TypeError: sequence item 0: expected str instance, bytes found
graph.execute_command('GRAPH.EXPLAIN', graph.name, 'match (n:person) where n.name = "ken" return n')

return

[b'Results',
 b'    Project',
 b'        Filter',
 b'            Node By Label Scan | (n:person)']

The problem is the result that type is List[byte].
I guess the code should modify as this:

    def explain(self, query, params=None):
        """
        Get the execution plan for given query,
        Returns an array of operations.
        For more information see `GRAPH.EXPLAIN <https://oss.redis.com/redisgraph/master/commands/#graphexplain>`_. # noqa

        Args:

        -------
        query:
            The query that will be executed.
        params: dict
            Query parameters.
        """
        if params is not None:
            query = self._build_params_header(params) + query

        plan = self.execute_command("GRAPH.EXPLAIN", self.name, query)
        return "\n".join([b.decode() for b in plan])

or

    def explain(self, query, params=None):
        """
        Get the execution plan for given query,
        Returns an array of operations.
        For more information see `GRAPH.EXPLAIN <https://oss.redis.com/redisgraph/master/commands/#graphexplain>`_. # noqa

        Args:

        -------
        query:
            The query that will be executed.
        params: dict
            Query parameters.
        """
        if params is not None:
            query = self._build_params_header(params) + query

        plan = self.execute_command("GRAPH.EXPLAIN", self.name, query)
        return plan
@chayim
Copy link
Contributor

chayim commented Jan 10, 2022

@ChandlerBent When you constructed your redis connection how did you set decode_responses?

import redis
r = redis.Redis(decode_responses=True)

or

import redis
r = redis.Redis()

Can you try setting decode_responses=True if not already set?

@ChandlerBent
Copy link
Author

@chayim Hi, Thank you.

I did not set decode_responses=True

But I think it should support decode_responses=False.

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

Successfully merging a pull request may close this issue.

2 participants