【问题标题】:Why I've got a error "Ref expected, Object provided"?为什么我有一个错误“预期参考,提供对象”?
【发布时间】:2019-09-18 13:13:54
【问题描述】:

使用 Python API,我在“spells”集合中创建了一个文档,如下所示

>>> 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}}

然后,我尝试获取带有 ts 的文档,如下所示:

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

但是,结果是“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.

我不知道哪里出了问题,欢迎提出任何建议!

【问题讨论】:

    标签: faunadb


    【解决方案1】:

    我自己解决了这个问题。我也错过了 q.ref 的参数。

    正确的参数如下:

    >>> 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}}
    

    【讨论】:

    • 是的。这就是答案。在错误的位置有一个)q.collection 只接受一个参数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-27
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    相关资源
    最近更新 更多