Xuanwo opened a new pull request, #8963:
URL: https://github.com/apache/opendal/pull/8963
# Which issue does this PR close?
None.
# Rationale for this change
Two configuration and URI-parsing bugs exist in `opendal-service-postgresql`:
1. **Dropped URI credentials and clobbered `root` option**:
`PostgresqlConfig::from_uri` synthesized `connection_string` from
`uri.authority()` without reading `uri.username()` or `uri.password()`,
silently dropping URI credentials. It also overwrote an explicit `root` option
with the URI path suffix via `map.insert("root", ...)` instead of preserving
explicit options.
2. **Missing build-time config and identifier validation**:
`PostgresqlBuilder::build` accepted empty/whitespace-only `connection_string`
values and empty or NUL-byte-containing `table`, `key_field`, and `value_field`
identifiers (for example via `PostgresqlConfig` or builder methods), causing
runtime SQL failures (`ErrorKind::Unexpected`) instead of failing fast with
`ErrorKind::ConfigInvalid`.
# What changes are included in this PR?
- Preserve percent-encoded `uri.username()` and `uri.password()` when
synthesizing `connection_string` in `PostgresqlConfig::from_uri` (matching
`opendal-service-mysql`), and use `map.entry("root").or_insert_with(...)` so
explicit `root` options take precedence over the URI path suffix.
- Document `PostgresqlConfig` URI construction semantics, including that the
synthesized `connection_string` omits a database path segment (PostgreSQL uses
`PGDATABASE` if set or defaults to the database matching the connecting
username; pass an explicit `connection_string` option to target another
database).
- Reject empty or whitespace-only `connection_string` and empty or
NUL-byte-containing `table`, `key_field`, and `value_field` in
`PostgresqlBuilder::build` with `ErrorKind::ConfigInvalid`.
- Add unit tests covering `from_uri` credential encoding/precedence and
`PostgresqlBuilder::build` validation.
# Are there any user-facing changes?
- `PostgresqlConfig::from_uri` now preserves percent-encoded URI credentials
in the synthesized `connection_string` and respects explicit `root` options.
Because the URI path maps to `table` and optional `root`, the synthesized
`connection_string` does not include a database path segment; PostgreSQL uses
`PGDATABASE` or defaults to a database matching the connecting username unless
an explicit `connection_string` option containing a database name is supplied.
- `PostgresqlBuilder::build` now rejects empty/whitespace-only
`connection_string` and empty or NUL-byte-containing `table`, `key_field`, and
`value_field` with `ErrorKind::ConfigInvalid`.
# Breaking changes
# AI Usage Statement
- Harness: pi
- Model: Gemini 4 Neon
- Effort: high
- Role: Implemented the `PostgresqlConfig::from_uri` and
`PostgresqlBuilder::build` fixes, documentation updates, and unit tests, and
verified changes against unit tests, rustdoc, clippy, and a local PostgreSQL
container.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]