Skip to content

Commit 092f015

Browse files
committed
fixing typo with start_connection_pool and close_connection_pool
1 parent 577a24d commit 092f015

File tree

5 files changed

+60
-14
lines changed

5 files changed

+60
-14
lines changed

docs/src/piccolo/engines/postgres_engine.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ pool in the shutdown event handler.
4747
@app.on_event('startup')
4848
async def open_database_connection_pool():
4949
engine = engine_finder()
50-
await engine.start_connnection_pool()
50+
await engine.start_connection_pool()
5151
5252
5353
@app.on_event('shutdown')
5454
async def close_database_connection_pool():
5555
engine = engine_finder()
56-
await engine.close_connnection_pool()
56+
await engine.close_connection_pool()
5757
5858
.. hint:: Using a connection pool helps with performance, since connections
5959
are reused instead of being created for each query.
@@ -74,7 +74,7 @@ adapter. Here's an example:
7474
.. code-block:: python
7575
7676
# To increase the number of connections available:
77-
await engine.start_connnection_pool(max_size=20)
77+
await engine.start_connection_pool(max_size=20)
7878
7979
-------------------------------------------------------------------------------
8080

piccolo/apps/asgi/commands/templates/starlette/_fastapi_app.py.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ async def delete_task(task_id: int):
7777
@app.on_event("startup")
7878
async def open_database_connection_pool():
7979
engine = engine_finder()
80-
await engine.start_connnection_pool()
80+
await engine.start_connection_pool()
8181

8282

8383
@app.on_event("shutdown")
8484
async def close_database_connection_pool():
8585
engine = engine_finder()
86-
await engine.close_connnection_pool()
86+
await engine.close_connection_pool()

piccolo/apps/asgi/commands/templates/starlette/_starlette_app.py.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ app = Starlette(
3030
@app.on_event("startup")
3131
async def open_database_connection_pool():
3232
engine = engine_finder()
33-
await engine.start_connnection_pool()
33+
await engine.start_connection_pool()
3434

3535

3636
@app.on_event("shutdown")
3737
async def close_database_connection_pool():
3838
engine = engine_finder()
39-
await engine.close_connnection_pool()
39+
await engine.close_connection_pool()

piccolo/engine/postgres.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,26 @@ async def prep_database(self):
287287
)
288288

289289
###########################################################################
290+
# These typos existed in the codebase for a while, so leaving these proxy
291+
# methods for now to ensure backwards compatility.
290292

291293
async def start_connnection_pool(self, **kwargs) -> None:
294+
warnings.warn(
295+
"This is a typo - please upgrade to `start_connection_pool`. This "
296+
"proxy method will be retired in the future."
297+
)
298+
return await self.start_connection_pool()
299+
300+
async def close_connnection_pool(self, **kwargs) -> None:
301+
warnings.warn(
302+
"This is a typo - please upgrade to `close_connection_pool`. This "
303+
"proxy method will be retired in the future."
304+
)
305+
return await self.close_connection_pool()
306+
307+
###########################################################################
308+
309+
async def start_connection_pool(self, **kwargs) -> None:
292310
if self.pool:
293311
warnings.warn(
294312
"A pool already exists - close it first if you want to create "
@@ -299,7 +317,7 @@ async def start_connnection_pool(self, **kwargs) -> None:
299317
config.update(**kwargs)
300318
self.pool = await asyncpg.create_pool(**config)
301319

302-
async def close_connnection_pool(self) -> None:
320+
async def close_connection_pool(self) -> None:
303321
if self.pool:
304322
await self.pool.close()
305323
self.pool = None

tests/engine/test_pool.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
import asyncio
22

3+
from piccolo.engine.postgres import PostgresEngine
4+
35
from ..base import DBTestCase, postgres_only
46
from ..example_app.tables import Manager
57

68

79
@postgres_only
810
class TestPool(DBTestCase):
911
async def _create_pool(self):
10-
await Manager._meta.db.start_connnection_pool()
11-
await Manager._meta.db.close_connnection_pool()
12+
engine: PostgresEngine = Manager._meta.db
13+
14+
await engine.start_connection_pool()
15+
assert engine.pool is not None
16+
17+
await engine.close_connection_pool()
18+
assert engine.pool is None
1219

1320
async def _make_query(self):
14-
await Manager._meta.db.start_connnection_pool()
21+
await Manager._meta.db.start_connection_pool()
1522

1623
await Manager(name="Bob").save().run()
1724
response = await Manager.select().run()
1825
self.assertTrue("Bob" in [i["name"] for i in response])
1926

20-
await Manager._meta.db.close_connnection_pool()
27+
await Manager._meta.db.close_connection_pool()
2128

2229
async def _make_many_queries(self):
23-
await Manager._meta.db.start_connnection_pool()
30+
await Manager._meta.db.start_connection_pool()
2431

2532
await Manager(name="Bob").save().run()
2633

@@ -30,7 +37,7 @@ async def get_data():
3037

3138
await asyncio.gather(*[get_data() for _ in range(500)])
3239

33-
await Manager._meta.db.close_connnection_pool()
40+
await Manager._meta.db.close_connection_pool()
3441

3542
def test_creation(self):
3643
"""
@@ -50,3 +57,24 @@ def test_many_queries(self):
5057
exceed a connection limit - queries should queue, then succeed.
5158
"""
5259
asyncio.run(self._make_many_queries())
60+
61+
62+
@postgres_only
63+
class TestPoolProxyMethods(DBTestCase):
64+
async def _create_pool(self):
65+
engine: PostgresEngine = Manager._meta.db
66+
67+
# Deliberate typo ('nnn'):
68+
await engine.start_connnection_pool()
69+
assert engine.pool is not None
70+
71+
# Deliberate typo ('nnn'):
72+
await engine.close_connnection_pool()
73+
assert engine.pool is None
74+
75+
def test_proxy_methods(self):
76+
"""
77+
There are some proxy methods, due to some old typos. Make sure they
78+
work, to ensure backwards compatibility.
79+
"""
80+
asyncio.run(self._create_pool())

0 commit comments

Comments
 (0)