cockroachdb / docs

CockroachDB user documentation
https://cockroachlabs.com/docs
Creative Commons Attribution 4.0 International
187 stars 453 forks source link

Fix asyncpg rollback example #18015

Open dikshant opened 10 months ago

dikshant commented 10 months ago

Dikshant Adhikari (dikshant) commented:

https://github.com/cockroachdb/example-app-python-asyncpg/blob/main/example.py#L86

uses conn.rollback() which is not a thing. We are doing async with conn.transaction(): we should do async with conn.transaction() as t: and then t.rollback() instead of conn.rollback() because rollbacks are defined at the transaction level and not the connection level https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.transaction.Transaction

time.sleep should also be updated to use await async.io sleep as a best practie https://github.com/cockroachdb/example-app-python-asyncpg/blob/main/example.py#L90

Jira Issue: DOC-9106

exalate-issue-sync[bot] commented 10 months ago

Shannon Bradshaw (shannonbradshaw) commented: Dikshant Adhikari, in what context did you come across this?

exalate-issue-sync[bot] commented 10 months ago

Dikshant Adhikari (dikshant) commented: Shannon Bradshaw Someone from the community slack flagged it https://cockroachdb.slack.com/archives/C01LKHP0KS6/p1698181388311639

exalate-issue-sync[bot] commented 10 months ago

Richard Loveland (rmloveland) commented: Dikshant Adhikari I snagged this and added a prio, plz feel free to change it if you disagree