Search code examples
faunadb

Why I've got a error "Ref expected, Object provided"?


With Python API, I've created a document in the collection "spells" as follows

>>> client.query(
...   q.create(
...     q.collection("spells"),
...     {
...       "data": {"name": "Mountainous Thunder", "element": "air", "cost": 15}
...     }
...   ))
{'ref': Ref(id=243802653698556416, collection=Ref(id=spells, collection=Ref(id=collections))), 'ts': 1568767179200000, 'data': {'name': 'Mountainous Thunder', 'element': 'air', 'cost': 15}}

Then, I've tried to get the document with its ts as follows:

>>> client.query(q.get(q.ref(q.collection("spells", "1568767179200000"))))

But, the result is, the error as "Ref expected, Object provided".

>>> client.query(q.get(q.ref(q.collection("spells", "1568767179200000"))))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/faunadb/client.py", line 175, in query
    return self._execute("POST", "", _wrap(expression), with_txn_time=True)
  File "/usr/local/lib/python3.6/dist-packages/faunadb/client.py", line 242, in _execute
    FaunaError.raise_for_status_code(request_result)
  File "/usr/local/lib/python3.6/dist-packages/faunadb/errors.py", line 28, in raise_for_status_code
    raise BadRequest(request_result)
faunadb.errors.BadRequest: Ref expected, Object provided.

I've no idea what was wrong, any suggestions are welcome!


Solution

  • I've solved this myself. I've also missed parameters with q.ref.

    The correct params are as follows:

    >>> client.query(q.get(q.ref(q.collection("spells"),"243802585534824962")))
    
    {'ref': Ref(id=243802585534824962, collection=Ref(id=spells, collection=Ref(id=collections))), 'ts': 1568767114140000, 'data': {'name': 'Mountainous Thunder', 'element': 'air', 'cost': 15}}