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

Docs/Message improvements (eg, "no method named `on_conflict` found for type OwnedBatchInsert") #1797

Closed
bnewbold opened this Issue Jul 26, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@bnewbold

bnewbold commented Jul 26, 2018

I had a piece of code like this:

let new_abstracts: Vec<AbstractsRow> = ...
insert_into(abstracts::table)
                    .values(new_abstracts)
                    .on_conflict(abstracts::sha1)
                    .do_nothing()
                    .execute(conn)?;

which was giving me errrors like:

error[E0599]: no method named `on_conflict` found for type `diesel::query_builder::InsertStatement<database_schema::abstracts::table, diesel::insertable::OwnedBatchInsert<diesel::query_builder::ValuesClause<(diesel::insertable::ColumnInsertValue<database_schema::abstracts::columns::sha1, diesel::expression::bound::Bound<diesel::sql_types::Text, std::string::String>>, diesel::insertable::ColumnInsertValue<database_schema::abstracts::columns::content, diesel::expression::bound::Bound<diesel::sql_types::Text, std::string::String>>), database_schema::abstracts::table>>>` in the current scope
   --> src/api_server.rs:811:22
    |
811 |                     .on_conflict(abstracts::sha1)
    |                      ^^^^^^^^^^^
    |
    = note: the method `on_conflict` exists but the following trait bounds were not satisfied:
            `diesel::insertable::OwnedBatchInsert<diesel::query_builder::ValuesClause<(diesel::insertable::ColumnInsertValue<database_schema::abstracts::columns::sha1, diesel::expression::bound::Bound<diesel::sql_types::Text, std::string::String>>, diesel::insertable::ColumnInsertValue<database_schema::abstracts::columns::content, diesel::expression::bound::Bound<diesel::sql_types::Text, std::string::String>>), database_schema::abstracts::table>> : diesel::query_builder::UndecoratedInsertRecord<database_schema::abstracts::table>`

which I found really opaque. Eventually I found that passing the rows by reference (.values(&new_abstracts)) fixed the error.

I'd like to contribute an improved error message and/or note in the documentation for on_conflict(), as a first-time contributor, but I don't know enough about diesel internals to know if this makes sense. The error message looks like a rust type-system thing, and I don't know if there is a way to hook in to that.

I'd be happy to contribute more such error message improvements if it's possible. I have enjoyed using Diesel for this project, but have run in to a lot of very long compile error messages, and think it would be a huge win if they could be improved.

Versions

  • Rust: 1.27.2
  • Diesel: 1.3.2
  • Database: Postgres 10
  • Operating System: Linux (Debian stretch)
  • Feature Flags: diesel = { version = "1.3.2", features = ["postgres", "uuid", "serde_json", "chrono", "r2d2"] }
@bnewbold

This comment has been minimized.

bnewbold commented Jul 26, 2018

Splunking around some more, I see previous discussion of some other compile-time messages, notably in #151 ("Examine our compiler errors, and see if we can improve them") and #573 ("See if we can catch common errors with a lint").

@sgrif

This comment has been minimized.

Member

sgrif commented Jul 26, 2018

Unfortunately, this is an error generated by Rust in general and not something we have any control over. Feel free to open an issue on the Rust repo if you think this is actionable for them.

@sgrif sgrif closed this Jul 26, 2018

@sgrif

This comment has been minimized.

Member

sgrif commented Jul 26, 2018

(The problem is likely that you forgot an & in the call to values which we do try and call out will generally lead to more opaque than average error messages)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment