diesel: impl std::fmt::Debug for diesel::pg::PgConnection

Feature Description

impl std::fmt::Debug for diesel::pg::PgConnection {
    // ...
}

Possible solution

My idea would be to just store the database_url on PgConnection::establish(database_url) in the PgConnection and use it as the debug message. But I am open to include additional information.

Happy to implement it myself 😁

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (23 by maintainers)

Most upvoted comments

It’s not about the application knowing the database_url but about the secrets being logged because of unwrap or expect

Yeah, we do that by implementing a custom Debug for ConnectionManager which means we can skip the Connection debug there which means there is no reason for this issue and related PR to exist.

I agree that we should have a custom Debug for ConnectionManager<T> which doesn’t need T: Debug. Thereby we enable easier use of static DB: OnceCell: Pool<ConnectionManager<PgConnection>>>.

But static DB: OnceCell<PgConnection> would not work. If this isn’t a common pattern we can drop #2572, but I am unsure about that. Need your experience here… --> Just made a github-wide code search and only could find usage of static DB: Pool<...>. Going to close PR.

You would need to change r2d2 too and forward the debug IIUC

Pool and ConnectionManager already implement Debug, but require the enclosed type to also implement it.

Ok then let me word it that way: I would be happy to merge a PR implementing Debug for all connection types as long as it does not reveal potentially confidential information. I consider database url’s to be potential confidential here.

ā€œJustā€ dropping the password/username there would mean that you have to parse the url. That’s quite a lot of complexity for such a simple feature. Additionally I’m not sure that the password field is the only potential confidential field there. What’s for example with ssl based authentication?