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

Regression: the trait PgHasArrayType is not implemented for serde_json::Value #1721

Closed
abreis opened this issue Feb 22, 2022 · 5 comments · Fixed by #1722
Closed

Regression: the trait PgHasArrayType is not implemented for serde_json::Value #1721

abreis opened this issue Feb 22, 2022 · 5 comments · Fixed by #1722
Labels
db:postgres Related to PostgreSQL regression Something worked before but doesn't now

Comments

@abreis
Copy link
Contributor

abreis commented Feb 22, 2022

After an update to sqlx 0.5.10 I'm now seeing this error:

error[E0277]: the trait bound `serde_json::Value: PgHasArrayType` is not satisfied
   --> pkg/database/src/app.rs:141:15
    |
141 |         .bind(col_fields)
    |          ---- ^^^^^^^^^^ the trait `PgHasArrayType` is not implemented for `serde_json::Value`
    |          |
    |          required by a bound introduced by this call
    |
    = note: required because of the requirements on the impl of `PgHasArrayType` for `std::option::Option<serde_json::Value>`
    = note: required because of the requirements on the impl of `Type<Postgres>` for `Vec<std::option::Option<serde_json::Value>>`

The underlying code is trying to bind() a Vec<Option<JsonValue>> for an UNNEST statement.

Cargo.toml is:

sqlx = { version = "=0.5.10", default-features = false, features = ["postgres", "chrono", "decimal", "json", "uuid", "runtime-tokio-native-tls", "macros", "migrate", "offline"] }

Reverting to sqlx 0.5.7 makes the error go away.

If there's anything I can do to help track this down please let me know. Thanks!

@abonander
Copy link
Collaborator

Seems to be a bad interaction between various changes in #1385

I think adding a PgHasArrayType impl for JsonValue will fix it. You could just copy the one for Json<T>.

@abonander abonander added db:postgres Related to PostgreSQL regression Something worked before but doesn't now labels Feb 22, 2022
@abreis
Copy link
Contributor Author

abreis commented Feb 22, 2022

I gave it a try but now there's a couple conflicting impls (between [T] where T: PgHasArrayType and [JsonValue]). Perhaps one of those is no longer needed after #1385.

error[E0119]: conflicting implementations of trait `types::Type<postgres::database::Postgres>` for type `[serde_json::Value]`
  --> /Users/abreis/.cargo/git/checkouts/sqlx-28e322958903bd10/97b68a4/sqlx-core/src/postgres/types/array.rs:31:1
   |
31 | / impl<T> Type<Postgres> for [T]
32 | | where
33 | |     T: PgHasArrayType,
34 | | {
...  |
41 | |     }
42 | | }
   | |_^ conflicting implementation for `[serde_json::Value]`
   |
  ::: /Users/abreis/.cargo/git/checkouts/sqlx-28e322958903bd10/97b68a4/sqlx-core/src/types/json.rs:73:1
   |
73 | / impl<DB> Type<DB> for [JsonValue]
74 | | where
75 | |     [Json<JsonValue>]: Type<DB>,
76 | |     DB: Database,
...  |
84 | |     }
85 | | }
   | |_- first implementation here

@abonander
Copy link
Collaborator

abonander commented Feb 22, 2022

Another possibility might be to change this bound: https://github.com/launchbadge/sqlx/blob/master/sqlx-core/src/postgres/types/array.rs#L20

to [T]: Type<Postgres>, which should hopefully not break anything else?

@jplatte
Copy link
Contributor

jplatte commented Feb 22, 2022

but now there's a couple conflicting impls

Yeah it looks like impl<DB> Type<DB> for Vec<JsonValue> and impl<DB> Type<DB> for [JsonValue] are a thing. These might be the only DB-agnostic array impls? But they have bounds for the corresponding container with an item type of Json<JsonValue> implementing Type<DB>, so I think in the end they're only applicable to postgres anyways? If they are, they can safely be removed in favor of one PgHasArrayType impl for JsonValue.

@abreis
Copy link
Contributor Author

abreis commented Feb 22, 2022

That worked, let me open a PR to see if it nothing else broke.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db:postgres Related to PostgreSQL regression Something worked before but doesn't now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants