Skip to content

fix(spanner): make types module public for typed param construction#5912

Merged
olavloite merged 1 commit into
googleapis:mainfrom
thealtoclef:issue-5911
Jun 22, 2026
Merged

fix(spanner): make types module public for typed param construction#5912
olavloite merged 1 commit into
googleapis:mainfrom
thealtoclef:issue-5911

Conversation

@buu-nguyen

Copy link
Copy Markdown
Contributor

The google_cloud_spanner::types module was declared pub(crate), so the
documented primitive constructors (int64(), string(), timestamp(), bool(), bytes(), date(), float32(), float64(), json(), numeric(), uuid(), interval(), plus the PostgreSQL variants pg_numeric(), pg_jsonb(), pg_oid()) were unreachable from external crates. Downstream code calling StatementBuilder::add_typed_param was forced to construct values via the generated
google_cloud_spanner::model::Type
protobuf struct and field mutation, coupling external code to a #[non_exhaustive] generated type.

The module visibility was the only thing wrong: every constructor is already
pub fn inside the module, already documented at its declaration site in
src/spanner/src/types.rs, and already used internally by the SDK's own tests at src/spanner/src/statement.rs:390-394 via crate::types::string().
This was a classic Rust visibility gotcha where items declared pub were
hidden by a pub(crate) module.

Changed pub(crate) mod types to pub mod types at src/spanner/src/lib.rs:92.
Added an integration test (tests/types_module_visibility.rs) that exercises
the constructors from an external-crate perspective, so any future regression
that re-hides the module fails compilation with the same E0603 error downstream users reported.

Fixes #5911

@buu-nguyen buu-nguyen requested review from a team as code owners June 17, 2026 20:08
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Jun 17, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request changes the visibility of the types module in google-cloud-spanner from pub(crate) to pub and adds integration tests to verify that its public constructors are accessible externally. The reviewer recommends adding a doc comment to the newly public types module to comply with the repository's style guide.

Comment thread src/spanner/src/lib.rs Outdated
@buu-nguyen

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request changes the visibility of the types module in the google-cloud-spanner crate from internal (pub(crate)) to public (pub), exposing Spanner primitive type constructors for typed parameter binding. Additionally, it introduces a new integration test suite types_module_visibility.rs to verify the public accessibility of these constructors and prevent future visibility regressions. There are no review comments, so I have no feedback to provide.

@olavloite olavloite self-assigned this Jun 18, 2026
@olavloite

Copy link
Copy Markdown
Contributor

/gcbrun

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.90%. Comparing base (a042feb) to head (a549781).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5912   +/-   ##
=======================================
  Coverage   97.90%   97.90%           
=======================================
  Files         233      233           
  Lines       59202    59202           
=======================================
  Hits        57962    57962           
  Misses       1240     1240           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ding

The `google_cloud_spanner::types` module was declared `pub(crate)` and
lived in the `// Internal modules` section of `lib.rs`, so the documented
primitive constructors (`int64()`, `string()`, `timestamp()`, `bool()`,
`bytes()`, `date()`, `float32()`, `float64()`, `json()`, `numeric()`,
`uuid()`, `interval()`, plus the PostgreSQL variants `pg_numeric()`,
`pg_jsonb()`, `pg_oid()`) were unreachable from external crates.
Downstream code calling `StatementBuilder::add_typed_param` was forced to
construct values via the generated `google_cloud_spanner::model::Type`
protobuf struct and field mutation, coupling external code to a
`#[non_exhaustive]` generated type.

The module was the only thing wrong: every constructor is already
`pub fn` inside the module, already documented at its declaration site in
`src/spanner/src/types.rs`, and already used internally by the SDK's own
tests at `src/spanner/src/statement.rs:390-394` via `crate::types::string()`.
This was a classic Rust visibility gotcha where items declared `pub` were
hidden by a `pub(crate)` module, made worse by the module being filed in the
`// Internal modules` block of `lib.rs` even though its contents were part
of the documented public surface.

Moved `pub(crate) mod types` out of the internal block and re-declared it as
`pub mod types` in the `// Public domain modules` block, next to its
semantic peer `value` (which re-exports the type and traits but never the
constructors). Added a regression test in
`tests/types_module_visibility.rs` that exercises the constructors from an
external-crate perspective, so any future regression that re-hides the module
fails compilation with the same `E0603` error downstream users reported.

Towards googleapis#5911
@buu-nguyen

Copy link
Copy Markdown
Contributor Author

/gcbrun

@olavloite can you re-trigger this? Thanks.
I forgot to run cargo fmt, mb. Just did it and committed.

@sakthivelmanii

Copy link
Copy Markdown

/gcbrun

@olavloite olavloite requested a review from sakthivelmanii June 21, 2026 07:39
@olavloite olavloite merged commit fd3f7e2 into googleapis:main Jun 22, 2026
40 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Spanner] types module is pub(crate) — blocks external use of add_typed_param with primitive types

3 participants