Skip to content

Commit 4a97715

Browse files
gordthompsonrafiss
authored andcommitted
Apply updates for SQLA v2.0.38
1 parent 0911d4b commit 4a97715

File tree

4 files changed

+15
-97
lines changed

4 files changed

+15
-97
lines changed

README.asyncpg.md

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -9,82 +9,6 @@ There is a customized version of the FastAPI SQL database tutorial for
99

1010
https://github.com/gordthompson/fastapi-tutorial-cockroachdb-async
1111

12-
### Default transaction isolation level
13-
14-
Applications using asyncpg that were developed prior to CockroachDB's inclusion of
15-
READ COMMITTED transaction isolation may operate on the assumption that the default
16-
isolation level will be SERIALIZABLE. For example,
17-
18-
```python
19-
import asyncio
20-
21-
from sqlalchemy.ext.asyncio import create_async_engine
22-
23-
24-
async def async_main():
25-
engine = create_async_engine(
26-
"cockroachdb+asyncpg://root@localhost:26257/defaultdb",
27-
)
28-
async with engine.begin() as conn:
29-
result = await conn.exec_driver_sql("select version()")
30-
print(result.scalar().split("(")[0]) # CockroachDB CCL v23.2.4
31-
32-
result = await conn.exec_driver_sql("show transaction isolation level")
33-
print(result.scalar()) # serializable
34-
35-
36-
asyncio.run(async_main())
37-
```
38-
39-
With current versions of CockroachDB, the default transaction isolation level
40-
**for asyncpg only** is now READ COMMITTED
41-
42-
```python
43-
import asyncio
44-
45-
from sqlalchemy.ext.asyncio import create_async_engine
46-
47-
48-
async def async_main():
49-
engine = create_async_engine(
50-
"cockroachdb+asyncpg://root@localhost:26257/defaultdb",
51-
)
52-
async with engine.begin() as conn:
53-
result = await conn.exec_driver_sql("select version()")
54-
print(result.scalar().split("(")[0]) # CockroachDB CCL v24.3.0
55-
56-
result = await conn.exec_driver_sql("show transaction isolation level")
57-
print(result.scalar()) # read committed
58-
59-
60-
asyncio.run(async_main())
61-
```
62-
63-
Applications that rely on the original behavior will have to add `isolation_level="SERIALIZABLE"`
64-
to their `create_async_engine()` call
65-
66-
```python
67-
import asyncio
68-
69-
from sqlalchemy.ext.asyncio import create_async_engine
70-
71-
72-
async def async_main():
73-
engine = create_async_engine(
74-
"cockroachdb+asyncpg://root@localhost:26257/defaultdb",
75-
isolation_level="SERIALIZABLE",
76-
)
77-
async with engine.begin() as conn:
78-
result = await conn.exec_driver_sql("select version()")
79-
print(result.scalar().split("(")[0]) # CockroachDB CCL v24.3.0
80-
81-
result = await conn.exec_driver_sql("show transaction isolation level")
82-
print(result.scalar()) # serializable
83-
84-
85-
asyncio.run(async_main())
86-
```
87-
8812
### Testing
8913

9014
Assuming that you have an entry in test.cfg that looks something like

dev-requirements.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
backports-tarfile==1.2.0
22
# via jaraco-context
3-
certifi==2024.12.14
3+
certifi==2025.1.31
44
# via requests
55
cffi==1.17.1
66
# via cryptography
@@ -12,13 +12,15 @@ distlib==0.3.9
1212
# via virtualenv
1313
docutils==0.21.2
1414
# via readme-renderer
15-
filelock==3.16.1
15+
filelock==3.17.0
1616
# via
1717
# tox
1818
# virtualenv
19+
id==1.5.0
20+
# via twine
1921
idna==3.10
2022
# via requests
21-
importlib-metadata==8.5.0
23+
importlib-metadata==8.6.1
2224
# via
2325
# keyring
2426
# twine
@@ -38,7 +40,7 @@ markdown-it-py==3.0.0
3840
# via rich
3941
mdurl==0.1.2
4042
# via markdown-it-py
41-
more-itertools==10.5.0
43+
more-itertools==10.6.0
4244
# via
4345
# jaraco-classes
4446
# jaraco-functools
@@ -48,8 +50,6 @@ packaging==24.2
4850
# via
4951
# tox
5052
# twine
51-
pkginfo==1.12.0
52-
# via twine
5353
platformdirs==4.3.6
5454
# via virtualenv
5555
pluggy==1.5.0
@@ -66,6 +66,7 @@ readme-renderer==44.0
6666
# via twine
6767
requests==2.32.3
6868
# via
69+
# id
6970
# requests-toolbelt
7071
# twine
7172
requests-toolbelt==1.0.0
@@ -82,15 +83,15 @@ toml==0.10.2
8283
# via tox
8384
tox==3.23.1
8485
# via -r dev-requirements.in
85-
twine==6.0.1
86+
twine==6.1.0
8687
# via -r dev-requirements.in
8788
typing-extensions==4.12.2
8889
# via rich
8990
urllib3==2.3.0
9091
# via
9192
# requests
9293
# twine
93-
virtualenv==20.28.1
94+
virtualenv==20.29.1
9495
# via tox
9596
zipp==3.21.0
9697
# via importlib-metadata
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
from sqlalchemy.testing.provision import temp_table_keyword_args
2-
from sqlalchemy.testing.provision import update_db_opts
32

43

54
@temp_table_keyword_args.for_db("cockroachdb")
65
def _cockroachdb_temp_table_keyword_args(cfg, eng):
76
return {"prefixes": ["TEMPORARY"]}
8-
9-
10-
@update_db_opts.for_db("cockroachdb")
11-
def _update_db_opts(db_url, db_opts, options):
12-
"""Set database options (db_opts) for a test database that we created."""
13-
db_opts["isolation_level"] = "SERIALIZABLE"

test-requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
alembic==1.14.0
1+
alembic==1.14.1
22
# via -r test-requirements.in
33
async-timeout==5.0.1
44
# via asyncpg
55
asyncpg==0.30.0
66
# via -r test-requirements.in
7-
attrs==24.3.0
7+
attrs==25.1.0
88
# via pytest
99
futures==3.0.5
1010
# via -r test-requirements.in
1111
greenlet==3.1.1
1212
# via sqlalchemy
1313
iniconfig==2.0.0
1414
# via pytest
15-
mako==1.3.8
15+
mako==1.3.9
1616
# via alembic
1717
markupsafe==3.0.2
1818
# via mako
1919
mock==5.1.0
2020
# via -r test-requirements.in
21-
more-itertools==10.5.0
21+
more-itertools==10.6.0
2222
# via -r test-requirements.in
2323
packaging==24.2
2424
# via pytest
2525
pluggy==1.5.0
2626
# via pytest
27-
psycopg==3.2.3
27+
psycopg==3.2.4
2828
# via -r test-requirements.in
2929
psycopg2==2.9.10
3030
# via -r test-requirements.in
3131
py==1.11.0
3232
# via pytest
3333
pytest==7.1.3
3434
# via -r test-requirements.in
35-
sqlalchemy==2.0.37
35+
sqlalchemy==2.0.38
3636
# via
3737
# -r test-requirements.in
3838
# alembic

0 commit comments

Comments
 (0)