交易未进行,无法在API请求中使用.严重错误 [英] Transaction not in progress, cannot be used in API requests. FIRESTORE ERROR

查看:44
本文介绍了交易未进行,无法在API请求中使用.严重错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在firestore上学习交易,并且我对文档的示例功能进行了一些修改,但是我不确定为什么在进行不具有功能的交易时会出现交易未进行中..."的问题

I am learning transactions on firestore and I making some modifications to the sample functions of documentation but I'm not sure why I get "Transaction not in progress..." when I make transactions without a function

transaction = firestore_db.transaction()
doc_ref = firestore_db.collection(u'metadata').document(u'projects')

#@firestore.transactional
snapshot = doc_ref.get(transaction=transaction)
transaction.update(doc_ref, {
    u'count': snapshot.get(u'count') + 1
})

# [END update_data_transaction]

该错误是什么意思?我想对我的项目进行计数,以便在我的wep应用程序上对其进行分页,我希望用户可以在不同页面之间移动,而不仅仅是文档显示的上一页和下一页.谢谢您的时间!

What is the meaning of that error? I want to make a counter of my projects in order to paginate it on my wep app I would like the user can move between the different pages and not just prev and next as the documentation show. Thank you for your time!

推荐答案

函数,或者说修饰器 @ firestore.transactional 是逻辑的重要组成部分.该错误消息表示您没有启动事务,只是实例化了一个trnsaction对象.

The function, or better to say the decorator @firestore.transactional was an essential part of the logic. The error message means you didn't start the transaction, you've just instantiated a trnsaction object.

您可以使用 transaction._begin 手动开始交易,但是我强烈建议不要这样做.只需使用装饰器即可,该装饰器提供了用于管理事务的简单方法,包括例如错误处理.

You could begin the transaction manually using transaction._begin, but I'd strangly suggest against it. Just use the decorater which provides simple way to manage transactions, including for example error handling.

这篇关于交易未进行,无法在API请求中使用.严重错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆