Adding list of geo gives "Input for predicate location_olac of type scalar is uid"

Moved from GitHub pydgraph/24

Posted by dwhitena:

The parallel of this issue with the Go client: Adding array of geo gives "Input for predicate example.Loc of type scalar is uid" · Issue #11 · dgraph-io/dgo · GitHub, which I have reproduced in the Python client.

I created an index:

location_olac: [geo] @index(geo) .

and now I’m trying to add something like

'location_olac': [
  {
    'type': 'Point',
     'coordinates': [47.96056, -3.83472]
  },
  {
    'type': 'Point',
     'coordinates': [27.23453, -115.83472]
  },
]

I’m getting Input for predicate location_olac of type scalar is uid. If I take out one of the points (such that this is not a list), it works.

danielmai commented :

The parallel of this issue with the Go client: dgraph-io/dgo#11

This pending PR dgraph-io/dgraph#2485 mentioned in dgraph-io/dgo#11 should address this issue.

danielmai commented :

The pull request dgraph-io/dgraph#2485 has been merged. This issue is fixed as of Correctly handle a list of type geo in json (#2482) (#2485) · dgraph-io/dgraph@b1eb212 · GitHub.

import json

import pydgraph

client_stub = pydgraph.DgraphClientStub('localhost:9080')
client = pydgraph.DgraphClient(client_stub)

# Drop all data
op = pydgraph.Operation(drop_all=True)
client.alter(op)

# Set schema with geo index
schema = "location_olac: [geo] @index(geo) ."
op = pydgraph.Operation(schema=schema)
client.alter(op)

# Write list of points
txn = client.txn()
p = {
    'location_olac': [
        {
            'type': 'Point',
            'coordinates': [47.96056, -3.83472]
        },
        {
            'type': 'Point',
            'coordinates': [27.23453, -115.83472]
        },
    ]
}
assigned = txn.mutate(set_obj=p)
txn.commit()

# Query results
res = client.query('''{
 points(func: has(location_olac)) {
  expand(_all_)
 }
}''')

print json.loads(res.json)['points']

Results:

[{u'location_olac': [{u'type': u'Point', u'coordinates': [27.23453, -115.83472]}, {u'type': u'Point', u'coordinates': [47.96056, -3.83472]}]}]