feat(python): support exist_ok when creating secrets (#4978)

Add `exist_ok=False` to synchronous and asynchronous Python
`create_secret`. Passing `True` uses `CREATE SECRET IF NOT EXISTS`,
preserving an existing credential. The default continues to fail on an
existing name; rotation stays explicit through `alter_secret`.

```python
db.create_secret("api-key", value, exist_ok=True)
await async_db.create_secret("api-key", value, exist_ok=True)
```

The Rust API gains an awaitable builder with `.exist_ok(true)` while
existing `create_secret(...).await` calls keep working. Includes Python
SQL round-trip coverage and Rust coverage for direct and deferred SQL
responses.
This commit is contained in:
Jack Ye
2026-11-12 08:03:11 -08:00
committed by GitHub
parent ced4799ad5
commit 9e03bf97d4
12 changed files with 269 additions and 38 deletions
+3 -1
View File
@@ -1036,18 +1036,20 @@ impl Connection {
})
}
#[pyo3(signature = (name, value, namespace_path=None))]
#[pyo3(signature = (name, value, namespace_path=None, *, exist_ok=false))]
pub fn create_secret(
self_: PyRef<'_, Self>,
name: String,
value: String,
namespace_path: Option<Vec<String>>,
exist_ok: bool,
) -> PyResult<Bound<'_, PyAny>> {
let inner = self_.get_inner()?.clone();
let namespace_path = namespace_path.unwrap_or_default();
future_into_py(self_.py(), async move {
inner
.create_secret(name, value, &namespace_path)
.exist_ok(exist_ok)
.await
.infer_error()
})