Skip to content

fix(spanner): default parameter names to empty - #16045

Open
alaricd wants to merge 2 commits into
googleapis:mainfrom
alaricd:codex/spanner-parametername
Open

alaricd wants to merge 2 commits into
googleapis:mainfrom
alaricd:codex/spanner-parametername

Conversation

@alaricd

@alaricd alaricd commented Oct 29, 2026 •

Copy link
Copy Markdown

Summary

Initialize SpannerParameter.ParameterName to string.Empty and normalize null assignments back to the empty string. Add regression coverage for both cases.

Resolves #16043.

Microsoft contract

Microsoft documents the default value of DbParameter.ParameterName as an empty string: https://learn.microsoft.com/dotnet/api/system.data.common.dbparameter.parametername

Compatibility

This changes the observable value from null to empty for a new parameter and when null is assigned. Explicit non-null assignments are unchanged. Consumers that distinguish null from empty may observe the change; empty is the documented ADO.NET default and avoids null propagation through provider code.

Validation

dotnet test apis/Google.Cloud.Spanner.Data/Google.Cloud.Spanner.Data.Tests/Google.Cloud.Spanner.Data.Tests.csproj --no-restore -f net8.0 -p:NoWarn=CS8981%3BxUnit2004%3BxUnit2013 — 2,833 passed, 0 failed.

Discovery

Found using pengdows.AdoNetApiTest.conformance.

@alaricd
alaricd requested a review from a team as a code owner October 29, 2026 06:59
@google-cla

google-cla Bot commented Oct 29, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 initializes the ParameterName property of SpannerParameter to string.Empty by default and adds a corresponding unit test. The feedback highlights that setting ParameterName to null should also return string.Empty to comply with the ADO.NET specification, and suggests using a backing field to handle null coercion.


/// <inheritdoc />
public override string ParameterName { get; set; }
public override string ParameterName { get; set; } = string.Empty;

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.

medium

According to the ADO.NET specification for DbParameter.ParameterName, setting the property to null should also result in it returning an empty string (string.Empty). With an auto-implemented property, setting ParameterName to null will store and return null, which violates this contract and could lead to NullReferenceExceptions elsewhere. Consider using a backing field to coerce null values to string.Empty.

        private string _parameterName = string.Empty;
        public override string ParameterName
        {
            get => _parameterName;
            set => _parameterName = value ?? string.Empty;
        }

@alaricd
alaricd force-pushed the codex/spanner-parametername branch from 6f9a0f7 to 2051964 Compare October 29, 2026 07:25
@alaricd alaricd changed the title Default Spanner parameter names to empty fix(spanner): default parameter names to empty Oct 29, 2026
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Oct 29, 2026
@amanda-tarafa amanda-tarafa self-assigned this Oct 29, 2026
@amanda-tarafa
amanda-tarafa marked this pull request as draft October 29, 2026 16:28
@amanda-tarafa
amanda-tarafa self-requested a review October 29, 2026 16:29
@alaricd
alaricd marked this pull request as ready for review October 29, 2026 18:41

This branch has not been deployed

No deployments
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.

SpannerParameter.ParameterName should default to an empty string

2 participants