-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to specify a statement name in Connection.prepare() #846
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This adds the new `name` keyword argument to `Connection.prepare()` and `PreparedStatement.get_name()` method returning the name of a statement. Some users of asyncpg might find it useful to be able to control how prepared statements are named, especially when a custom prepared statement caching scheme is in use. Specifically, This should help with pgbouncer support in SQLAlchemy asyncpg dialect. Fixes: #837.
1st1
approved these changes
Nov 16, 2021
elprans
added a commit
that referenced
this pull request
Nov 16, 2021
Changes ------- * Improve SSL option compatibility in URIs (by @fantix in 383c711 for #827) * Add `Pool` methods to determine its min, max, current and idle size (by @elprans in 603e386 for #849) * Make it possible to specify a statement name in `Connection.prepare()` (by @elprans in 03a3d18 for #846) * Implement support for `multirange` types (by @elprans in d64a44a for #851) Fixes ----- * Make sure timeout callbacks always get cleaned up (by @elprans in dad2691 for #831) * Update `__all__` statements to a simpler form that is better supported by typecheckers (by @bschnurr in 0a3ae7f for #828) * Fix `test_timetz_encoding` on Python 3.10 (by @elprans in 3a90fef) * Fix a bunch of `ResourceWarnings` in the test suite (by @elprans in 2f4fe53) * Fix `SSLContext` deprecation warnings (by @elprans in 4d39a05) * Fix the description of the database argument to `connect()` (by @elprans in a2a9237 for #847) * Fix parsing of IPv6 addresses in the connection URI (by @elprans in f900b73 for #845) * Improve diagnostics of invalid `executemany()` input (by @elprans in a8fc21e for #848)
Merged
elprans
added a commit
that referenced
this pull request
Nov 16, 2021
Changes ------- * Improve SSL option compatibility in URIs (by @fantix in 383c711 for #827) * Add `Pool` methods to determine its min, max, current and idle size (by @elprans in 603e386 for #849) * Make it possible to specify a statement name in `Connection.prepare()` (by @elprans in 03a3d18 for #846) * Implement support for `multirange` types (by @elprans in d64a44a for #851) Fixes ----- * Make sure timeout callbacks always get cleaned up (by @elprans in dad2691 for #831) * Update `__all__` statements to a simpler form that is better supported by typecheckers (by @bschnurr in 0a3ae7f for #828) * Fix `test_timetz_encoding` on Python 3.10 (by @elprans in 3a90fef) * Fix a bunch of `ResourceWarnings` in the test suite (by @elprans in 2f4fe53) * Fix `SSLContext` deprecation warnings (by @elprans in 4d39a05) * Fix the description of the database argument to `connect()` (by @elprans in a2a9237 for #847) * Fix parsing of IPv6 addresses in the connection URI (by @elprans in f900b73 for #845) * Improve diagnostics of invalid `executemany()` input (by @elprans in a8fc21e for #848)
elprans
added a commit
that referenced
this pull request
Nov 16, 2021
Changes ------- * Improve SSL option compatibility in URIs (by @fantix in 383c711 for #827) * Add `Pool` methods to determine its min, max, current and idle size (by @elprans in 603e386 for #849) * Make it possible to specify a statement name in `Connection.prepare()` (by @elprans in 03a3d18 for #846) * Implement support for `multirange` types (by @elprans in d64a44a for #851) Fixes ----- * Make sure timeout callbacks always get cleaned up (by @elprans in dad2691 for #831) * Update `__all__` statements to a simpler form that is better supported by typecheckers (by @bschnurr in 0a3ae7f for #828) * Fix `test_timetz_encoding` on Python 3.10 (by @elprans in 3a90fef) * Fix a bunch of `ResourceWarnings` in the test suite (by @elprans in 2f4fe53) * Fix `SSLContext` deprecation warnings (by @elprans in 4d39a05) * Fix the description of the database argument to `connect()` (by @elprans in a2a9237 for #847) * Fix parsing of IPv6 addresses in the connection URI (by @elprans in f900b73 for #845) * Improve diagnostics of invalid `executemany()` input (by @elprans in a8fc21e for #848)
This was referenced Apr 6, 2023
sqlalchemy-bot
pushed a commit
to sqlalchemy/sqlalchemy
that referenced
this pull request
Apr 21, 2023
I faced an issue related to pg bouncer and prepared statement cache flow in asyncpg dialect. Regarding this discussion #6467 I prepared PR to support an optional parameter `name` in prepared statement which is allowed, since 0.25.0 version in `asyncpg` MagicStack/asyncpg#846 **UPD:** the issue with proposal: #9608 ### Description Added optional parameter `name_func` to `AsyncAdapt_asyncpg_connection` class which will call on the `self._connection.prepare()` function and populate a unique name. so in general instead this ```python from uuid import uuid4 from asyncpg import Connection class CConnection(Connection): def _get_unique_id(self, prefix: str) -> str: return f'__asyncpg_{prefix}_{uuid4()}__' engine = create_async_engine(..., connect_args={ 'connection_class': CConnection, }, ) ``` would be enough ```python from uuid import uuid4 engine = create_async_engine(..., connect_args={ 'name_func': lambda: f'__asyncpg_{uuid4()}__', }, ) ``` ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [ ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [x] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. **Have a nice day!** Fixes: #9608 Closes: #9607 Pull-request: #9607 Pull-request-sha: b4bc8d3 Change-Id: Icd753366cba166b8a60d1c8566377ec8335cd828
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the new
name
keyword argument toConnection.prepare()
andPreparedStatement.get_name()
method returning the name of a statement.Some users of asyncpg might find it useful to be able to control how
prepared statements are named, especially when a custom prepared
statement caching scheme is in use. Specifically, This should help with
pgbouncer support in SQLAlchemy asyncpg dialect.
Fixes: #837.