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"

Open
#15,907 3 comments 0 reactions 2 assignees Claimed by @sinhasubham View on GitHub
api: spanner priority: p3 type: question
Dominant language
Python
Stars
5.4k
Forks
1.8k
Avg merge
3d 4h
Merged PRs (30d)
122

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.