googleapis / googleapis/google-cloud-python

database: run_in_transaction with DQL (Data Query Language) statements seems impossible to use and produces "Transaction is not begun" and then "Transaction is already committed"

未关闭
#15,907 3 条评论 0 个 reaction 已指派 2 人 已被 @sinhasubham 认领 在 GitHub 查看
api: spanner priority: p3 type: question
主要语言
Python
星标
5.4k
派生
1.8k
平均合并
3 天 4 小时
30 天内合并 PR
122

描述

While working on battle testing for observability to inspect expected spans, I wrote this code

```python
def tx_dql_select(tx):
return tx.execute_sql("SELECT * FROM Singers")

fn = tx_dql_select
try:
result = database.run_in_transaction(fn)
if result and hasattr(result, "__iter__"):
for res in result:
print(res)
except Exception as e:
print(fn.__name__, e)
```

which produces

```shell
tx_dql_select Transaction is not begun
```

but when I add `tx.begin()` before the return I get back
```shell
tx_dql_select Transaction is already committed
```

It seems impossible to use, we need to figure out what's up. I should be able to run purely DQL in a transaction.

Kindly cc-ing @sakthivelmanii @harshachinta

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。