sfackler / rust-postgres

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

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

Closed lyang24 closed 1 month ago

lyang24 commented 1 month 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 1 month ago

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