Skip to content
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

PgAdvisoryLock missing necessary AsMut<PgConnection> #2520

Closed
conradludgate opened this issue May 31, 2023 · 1 comment
Closed

PgAdvisoryLock missing necessary AsMut<PgConnection> #2520

conradludgate opened this issue May 31, 2023 · 1 comment
Labels

Comments

@conradludgate
Copy link
Contributor

conradludgate commented May 31, 2023

Bug Description

https://docs.rs/sqlx/0.6.3/sqlx/postgres/struct.PgAdvisoryLock.html#method.acquire

A connection-like type is required to execute the call. Allowed types include PgConnection, PoolConnection and Transaction, as well as mutable references to any of these.

Neither Transaction<Postgres> nor PgConnection implement the required AsMut<PgConnection> trait.

Minimal Reproduction

pub fn demo<'l>(
    lock1: PgAdvisoryLockGuard<'l, PgConnection>,
    lock2: PgAdvisoryLockGuard<'l, Transaction<Postgres>>,
) {
}
error[E0277]: the trait bound `PgConnection: AsMut<PgConnection>` is not satisfied
   --> src/repositories/deposit/queries.rs:640:12
    |
640 |     lock1: PgAdvisoryLockGuard<'l, PgConnection>,
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsMut<PgConnection>` is not implemented for `PgConnection`
    |
note: required by a bound in `PgAdvisoryLockGuard`
   --> /Users/conrad.ludgate/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.6.3/src/postgres/advisory_lock.rs:80:42
    |
80  | pub struct PgAdvisoryLockGuard<'lock, C: AsMut<PgConnection>> {
    |                                          ^^^^^^^^^^^^^^^^^^^ required by this bound in `PgAdvisoryLockGuard`

error[E0277]: the trait bound `Transaction<'_, Postgres>: AsMut<PgConnection>` is not satisfied
   --> src/repositories/deposit/queries.rs:641:12
    |
641 |     lock2: PgAdvisoryLockGuard<'l, Transaction<Postgres>>,
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsMut<PgConnection>` is not implemented for `Transaction<'_, Postgres>`
    |
note: required by a bound in `PgAdvisoryLockGuard`
   --> /Users/conrad.ludgate/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.6.3/src/postgres/advisory_lock.rs:80:42
    |
80  | pub struct PgAdvisoryLockGuard<'lock, C: AsMut<PgConnection>> {
    |                                          ^^^^^^^^^^^^^^^^^^^ required by this bound in `PgAdvisoryLockGuard`

Info

  • SQLx version: 0.6.3
  • SQLx features enabled:
    • "chrono",
    • "offline",
    • "postgres",
    • "runtime-tokio-native-tls",
    • "macros",
    • "migrate",
    • "uuid",
    • "json",
    • "bigdecimal",
  • Database server and version: Postgres
  • Operating system: MacOS
  • rustc --version: 1.69.0
abonander pushed a commit that referenced this issue Jun 30, 2023
The documentation for `PgAdvisoryLockGuard` lists a set of types
that should be able to be passed to it, but when actually trying
to do so, compilation would fail due to missing `AsMut` trait
implementations for those types. This commit adds the missing
`AsMut` impls so that `Transaction` and `PgConnection` can be used
as type parameters to `PgAdvisoryLockGuard`, as expected.

For reference: #2520
@abonander
Copy link
Collaborator

Closed by #2554

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants