Why does my cypher query suddenly stop working?

I have been using this cypher function to retrieve all indexes from the graph and it has been working all well for a long time.

neo4j_driver = GraphDatabase.driver(self.uri, auth=(self.username, self.password), encrypted=False)
with self.neo4j_driver.session() as session:
            all_indexes = set()
            indexes = session.read_transaction(
                lambda tx:
                tx.run("CAll db.indexes"))
            for index in indexes:
                all_indexes.add(index[1])

This is part of my using the driver code. Today it suddenly stopped working, because the 'indexes' is always empty even though the graph does have a number of indexes created. I didn't do anything about the code or the neo4j Db itself. In figuring out of what might be the cause, I changed the code to the following:

with self.neo4j_driver.session() as session:
            all_indexes1 = set()
            indexes = session.run("""CAll db.indexes""")
            for result in indexes:
                all_indexes1.add(result[1])

            all_indexes2 = set()
            indexes = session.read_transaction(
                lambda tx:
                tx.run("CAll db.indexes"))
            for index in indexes:
                all_indexes2.add(index[1])

            print(len(all_indexes1), len(all_indexes2))

It turns out that all_indexes1 is not empty as expected, but all_indexes2 is empty, which is puzzling. What could cause this? I don't think I changed anything to cause this.

Hello @lingvisa :slight_smile:

I will share some of my code with you (you can only use bolt_to_list if you prefer to work with a list of dict or use bolt_to_df if you want to get a DataFrame):

def bolt_to_list(result):
    """
    Function to transform BOLT result into list of dictionnaries.
    """
    return [r.data() for r in result]


def bolt_to_df(result):
    """
    Function to transform BOLT result into DataFrame.
    """
    return pd.DataFrame(bolt_to_list(result))

To get list of indexes, I then do like this:

with self.neo4j_driver.session() as session:
    indexes = bolt_to_df(ses.run("CALL db.indexes"))

Regards,
Cobra

1 Like