'list' object has no attribute 'query'

Moved from GitHub pydgraph/97

Posted by AshNL:

Python 3, pydgraph 2.0.2
I’m playing around with Dgraph and am trying to do a simple query, but I can’t figure out where it goes wrong. The query function:

def dgraph_search(dgraph_client):
    query = """{
        updates(func: uid(0x1)) {
            hashed_key
            title
            mentions {
                expand(_all_)
            }
        }
    }"""
    res = dgraph_client.txn(read_only=True).query(query)
    updates = json.loads(res.json)

Client creation:

    dgraph_stub_1 = create_dgraph_stub('localhost:9080')
    dgraph_stub_2 = create_dgraph_stub('localhost:9081')
    dgraph_client = create_dgraph_client([dgraph_stub_1, dgraph_stub_2])
    print("Dgraph client created")
    
    dgraph_search(dgraph_client)

def create_dgraph_stub(dgraph_alpha_address):
    return pydgraph.DgraphClientStub(dgraph_alpha_address)

def create_dgraph_client(dgraph_stub):
    return pydgraph.DgraphClient(dgraph_stub)

As far as I can tell the client is created just fine. Running the query gives me the following error:

Error: 'list' object has no attribute 'query'

What obvious thing am I missing here?

AshNL commented :

Ugh nevermind, the client was not created successfully. My bad. Everything works as it should.