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

Problems debugging SQL when using serde_json::Value and/or uuid::Uuid #1126

Closed
bcmyers opened this Issue Aug 23, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@bcmyers

bcmyers commented Aug 23, 2017

Setup

Versions

  • Rust: 1.21.0-nightly (4fdb4bedf 2017-08-21)
  • Diesel: 0.15.2
  • Database: Postgres 9.6.4
  • Operating System: Mac OS 10.12.6
  • Other dependencies:
    --chrono: 0.4.0
    --serde_json: 1.0.2
    --uuid: 0.5.1

Feature Flags

  • diesel: ["chrono", "postgres", "serde_json", "uuid"]
  • diesel_codegen: ["postgres"]

Problem Description

It seems you are deprecating the debug_sql! macro in favor of a debug_query function; so perhaps this won't be an issue for long or is in fact no longer an issue.

That said, while running 0.15.2, it appears I'm unable to use debug_sql! with a struct that includes fields of type serde_json::Value and/or uuid::Uuid.

More specifically, when I try this:

extern crate chrono;
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_codegen;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate uuid;

use diesel::prelude::*;

use models::{Organization, Role};
use schema::{self, users};

#[derive(AsChangeset, Associations, Clone, Debug, Identifiable, Queryable)]
#[changeset_options(treat_none_as_null = "true")]
#[belongs_to(Organization, Role)]
pub struct User {
    pub id:                 uuid::Uuid,
    pub created_at:         chrono::DateTime<chrono::Utc>,
    pub updated_at:         chrono::DateTime<chrono::Utc>,
    pub email:              String,
    pub first_name:         String,
    pub last_name:          String,
    pub organization_id:    Option<uuid::Uuid>,
    pub password_hash:      String,
    pub regulatory_details: Option<serde_json::Value>,
    pub role_id:            uuid::Uuid,
    pub title:              Option<String>,
    pub username:           String,
}

pub fn debug(updated_user: &User) {
    let sql = diesel::update(users::table.filter(users::id.eq(updated_user.id))).set(updated_user);
    let s = debug_sql!(sql).to_string();
    println!("{}", s);
}

I get the following errors:

the trait `diesel::types::ToSql<diesel::types::Uuid, diesel::backend::Debug>` is not implemented for `uuid::Uuid`

the trait `diesel::types::ToSql<diesel::types::Json, diesel::backend::Debug>` is not implemented for `serde_json::Value`

Just filing this as an issue so that when you update the code base to use debug_query instead of debug_sql! you don't forget to test against feature types such as serde_json::Value and uuid::Uuid.

Thanks!

Checklist

  • I have already looked over the issue tracker for similar issues.
@Eijebong

This comment has been minimized.

Member

Eijebong commented Aug 23, 2017

Yeah, this won't be an issue anymore with the new debug_query

The error is basically saying that rust doesn't know how to serialize the Uuid type for the Debug backend (which has been removed)

Here is what it would look like (I only kept id and role_id)

UPDATE \"users\" SET \"role_id\" = $1 WHERE \"users\".\"id\" = $2 -- binds: [Uuid(\"5487ef73-fe8a-47d0-b573-c2c13a05ae47\"), Uuid(\"91e63d03-d4fe-40ea-97da-392c96c4cf11\")]

@Eijebong Eijebong closed this Aug 23, 2017

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