sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.52k stars 446 forks source link

regression: upgrade to tokio-postgres 0.7.11 introduced regression on SimpleQueryMessage enum #1168

Closed lyang24 closed 3 months ago

lyang24 commented 3 months ago

Hey @sfackler, I noticed some strange behavior after upgrade to postgres 0.7.11 (postgres-types from 0.26->0.27, postgres-protocol from 0.66->0.67). For an example the query below will panic because the result from simple_query is rather RowDescription variant instead of SimpleQueryMessage::Row is this expected?

 let _ = client
        .simple_query("CREATE TABLE test(b BLOB, ts TIMESTAMP TIME INDEX)")
        .await
        .unwrap();
    let _ = client
        .simple_query("INSERT INTO test VALUES(X'6162636b6c6d2aa954', 0)")
        .await
        .unwrap();
    let get_row = |mess: Vec<SimpleQueryMessage>| -> String {
        match &mess[0] {
            SimpleQueryMessage::Row(row) => row.get(0).unwrap().to_string(),
            _ => unreachable!(),
        }
    };

    let r = client.simple_query("SELECT b FROM test").await.unwrap();
    let b = get_row(r);
    assert_eq!(b, "\\x6162636b6c6d2aa954");
sfackler commented 3 months ago

Yes, that is expected. SimpleQueryMessage is #[non_exhaustive] specifically so that new variants can be added, and consumers should expect that.