Skip to content

Commit 592cecb

Browse files
sjwiesmanclaude
andauthored
fix clippy on main (#37042)
## Motivation `cargo clippy -p mz-deploy` surfaced 7 `clippy::disallowed_methods` warnings. The crate was calling `tokio_postgres` query/execute methods directly, which `clippy.toml` disallows repo-wide in favor of the `mz_postgres_util` `Sql` wrappers — these force SQL through the validated `Sql` type rather than raw strings. ## Changes - **`src/mz-deploy/Cargo.toml`** — add `mz-postgres-util` as a path dependency (single-line `Cargo.lock` change, no version bumps). - **`src/client/connection.rs`** — the five pass-through wrapper methods (`execute`, `query_one`, `query`, `simple_query`, `batch_execute`) now delegate to `mz_postgres_util::*`. Every call site passes string SQL (no prepared `Statement`), so the generic `ToStatement` bound is replaced with `&str`, wrapped via `Sql::raw_unchecked` — the sanctioned constructor for internally-assembled, already-trusted SQL. - **`src/client/deployment_ops.rs`** — the two raw `Transaction` calls (the `SUBSCRIBE` cursor `execute` and the `FETCH ALL` `query`) go through `mz_postgres_util::execute`/`query`; the static `"FETCH ALL c"` uses `Sql::new`. - **`src/client/errors.rs`** — add `From<mz_postgres_util::PostgresError> for ConnectionError`, mapping the `Postgres` variant back to `ConnectionError::Query` so the existing rich `as_db_error()` formatting is preserved. ## Testing No behavioral change; this is a lint-compliance refactor that preserves the existing public API and error formatting of the `Client` wrapper. `cargo clippy -p mz-deploy --all-targets -- -D warnings` now passes clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 63f4680 commit 592cecb

5 files changed

Lines changed: 51 additions & 41 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mz-deploy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ rayon = { workspace = true }
2020
junit-report = { workspace = true }
2121
mz-build-info = { path = "../build-info" }
2222
mz-ore = { path = "../ore", default-features = false, features = ["async"] }
23+
mz-postgres-util = { path = "../postgres-util" }
2324
mz-aws-util = { path = "../aws-util", default-features = false }
2425
mz-catalog = { path = "../catalog" }
2526
mz-controller-types = { path = "../controller-types" }

src/mz-deploy/src/client/connection.rs

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@
3838
use crate::client::errors::ConnectionError;
3939
use crate::config::{Profile, SslMode};
4040
use crate::info;
41+
use mz_postgres_util::Sql;
4142
use std::collections::BTreeMap;
4243
use tokio_postgres::types::ToSql;
43-
use tokio_postgres::{
44-
Client as PgClient, NoTls, Row, SimpleQueryMessage, ToStatement, Transaction,
45-
};
44+
use tokio_postgres::{Client as PgClient, NoTls, Row, SimpleQueryMessage, Transaction};
4645

4746
/// Database client for interacting with Materialize.
4847
///
@@ -242,67 +241,65 @@ impl Client {
242241
}
243242

244243
/// Execute a SQL statement that doesn't return rows.
245-
pub async fn execute<T>(
244+
pub async fn execute(
246245
&self,
247-
statement: &T,
246+
statement: &str,
248247
params: &[&(dyn ToSql + Sync)],
249-
) -> Result<u64, ConnectionError>
250-
where
251-
T: ?Sized + ToStatement,
252-
{
253-
self.client
254-
.execute(statement, params)
255-
.await
256-
.map_err(ConnectionError::Query)
248+
) -> Result<u64, ConnectionError> {
249+
mz_postgres_util::execute(
250+
&self.client,
251+
Sql::raw_unchecked(statement.to_string()),
252+
params,
253+
)
254+
.await
255+
.map_err(ConnectionError::from)
257256
}
258257

259258
/// Execute a SQL query and return the resulting rows.
260-
pub async fn query_one<T>(
259+
pub async fn query_one(
261260
&self,
262-
statement: &T,
261+
statement: &str,
263262
params: &[&(dyn ToSql + Sync)],
264-
) -> Result<Row, ConnectionError>
265-
where
266-
T: ?Sized + ToStatement,
267-
{
268-
self.client
269-
.query_one(statement, params)
270-
.await
271-
.map_err(ConnectionError::Query)
263+
) -> Result<Row, ConnectionError> {
264+
mz_postgres_util::query_one(
265+
&self.client,
266+
Sql::raw_unchecked(statement.to_string()),
267+
params,
268+
)
269+
.await
270+
.map_err(ConnectionError::from)
272271
}
273272

274273
/// Execute a SQL query and return the resulting rows.
275-
pub async fn query<T>(
274+
pub async fn query(
276275
&self,
277-
statement: &T,
276+
statement: &str,
278277
params: &[&(dyn ToSql + Sync)],
279-
) -> Result<Vec<Row>, ConnectionError>
280-
where
281-
T: ?Sized + ToStatement,
282-
{
283-
self.client
284-
.query(statement, params)
285-
.await
286-
.map_err(ConnectionError::Query)
278+
) -> Result<Vec<Row>, ConnectionError> {
279+
mz_postgres_util::query(
280+
&self.client,
281+
Sql::raw_unchecked(statement.to_string()),
282+
params,
283+
)
284+
.await
285+
.map_err(ConnectionError::from)
287286
}
288287

289288
/// Execute a SQL statement using the simple query protocol (text-only, no binary encoding).
290289
pub async fn simple_query(
291290
&self,
292291
query: &str,
293292
) -> Result<Vec<SimpleQueryMessage>, ConnectionError> {
294-
self.client
295-
.simple_query(query)
293+
mz_postgres_util::simple_query(&self.client, Sql::raw_unchecked(query.to_string()))
296294
.await
297-
.map_err(ConnectionError::Query)
295+
.map_err(ConnectionError::from)
298296
}
299297

300298
/// Execute one or more SQL statements that don't return rows, using the simple query protocol.
301299
pub async fn batch_execute(&self, query: &str) -> Result<(), ConnectionError> {
302-
self.client
303-
.batch_execute(query)
300+
mz_postgres_util::batch_execute(&self.client, Sql::raw_unchecked(query.to_string()))
304301
.await
305-
.map_err(ConnectionError::Query)
302+
.map_err(ConnectionError::from)
306303
}
307304
}
308305

src/mz-deploy/src/client/deployment_ops.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ use crate::project::ir::object_id::ObjectId;
7171
use async_stream::try_stream;
7272
use chrono::{DateTime, Utc};
7373
use futures::Stream;
74+
use mz_postgres_util::Sql;
7475
use std::collections::{BTreeMap, BTreeSet};
7576
use std::fmt;
7677
use tokio_postgres::types::ToSql;
@@ -1541,10 +1542,11 @@ impl DeploymentsClientMut<'_> {
15411542
"DECLARE c CURSOR FOR SUBSCRIBE ({query})"
15421543
);
15431544

1544-
txn.execute(&subscribe_sql, &[&pattern]).await?;
1545+
let subscribe_sql = Sql::raw_unchecked(subscribe_sql);
1546+
mz_postgres_util::execute(&txn, subscribe_sql, &[&pattern]).await?;
15451547

15461548
loop {
1547-
let rows = txn.query("FETCH ALL c", &[]).await?;
1549+
let rows = mz_postgres_util::query(&txn, Sql::new("FETCH ALL c"), &[]).await?;
15481550
if rows.is_empty() {
15491551
continue;
15501552
}

src/mz-deploy/src/client/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ impl From<tokio_postgres::Error> for ConnectionError {
154154
}
155155
}
156156

157+
impl From<mz_postgres_util::PostgresError> for ConnectionError {
158+
fn from(error: mz_postgres_util::PostgresError) -> Self {
159+
match error {
160+
mz_postgres_util::PostgresError::Postgres(error) => ConnectionError::Query(error),
161+
other => ConnectionError::Message(other.to_string()),
162+
}
163+
}
164+
}
165+
157166
/// Errors that can occur during project validation against the database.
158167
#[derive(Debug)]
159168
pub enum DatabaseValidationError {

0 commit comments

Comments
 (0)