Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b14653

Browse files
authored
Make prepare() not use named statements by default when cache is disabled (#1245)
We allow disabling the statement cache to circumvent a proxy's inability to cope with them, however there are still some holes where the use of a named statement is attempted: `prepare()` with the default arguments, and `copy_in()`. Fix both so that the use of a named statement is dependent upon whether the prepared statement cache is enabled. Fixes: #1219 Closes: #1218
1 parent 0525b53 commit 5b14653

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

‎asyncpg/connection.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ async def _get_statement(
405405
query,
406406
timeout,
407407
*,
408-
named=False,
408+
named: typing.Union[str, bool, None] =False,
409409
use_cache=True,
410410
ignore_custom_codec=False,
411411
record_class=None
@@ -639,24 +639,25 @@ async def prepare(
639639
query,
640640
name=name,
641641
timeout=timeout,
642-
use_cache=False,
643642
record_class=record_class,
644643
)
645644

646645
async def _prepare(
647646
self,
648647
query,
649648
*,
650-
name=None,
649+
name: typing.Union[str, bool, None] =None,
651650
timeout=None,
652651
use_cache: bool=False,
653652
record_class=None
654653
):
655654
self._check_open()
655+
if name is None:
656+
name = self._stmt_cache_enabled
656657
stmt = await self._get_statement(
657658
query,
658659
timeout,
659-
named=TrueifnameisNoneelsename,
660+
named=name,
660661
use_cache=use_cache,
661662
record_class=record_class,
662663
)
@@ -1115,7 +1116,7 @@ async def copy_records_to_table(self, table_name, *, records,
11151116
intro_query = 'SELECT {cols} FROM {tab} LIMIT 1'.format(
11161117
tab=tabname, cols=col_list)
11171118

1118-
intro_ps = await self._prepare(intro_query, use_cache=True)
1119+
intro_ps = await self.prepare(intro_query)
11191120

11201121
cond = self._format_copy_where(where)
11211122
opts = '(FORMAT binary)'

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /