Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpannerConnectionStringBuilder.ConversionOptions are set inconsistently #9158

Closed
jskeet opened this issue Sep 27, 2022 · 4 comments · Fixed by #9276
Closed

SpannerConnectionStringBuilder.ConversionOptions are set inconsistently #9158

jskeet opened this issue Sep 27, 2022 · 4 comments · Fixed by #9276
Assignees
Labels
api: spanner Issues related to the Spanner API. type: cleanup An internal cleanup or hygiene concern.

Comments

@jskeet
Copy link
Collaborator

jskeet commented Sep 27, 2022

When SpannerConnection.ConnectionString is set, it calls the SpannerConnectionStringBuilder(string, ChannelCredential, SessionPoolManager) constructor... whereas the Clone() method explicitly copies ConversionOptions from the source.

It's unclear whether setting SpannerConnectionStringBuilder.ConnectionString uses the indexer to set each value (in which case we don't need to copy it in Clone) or whether it's lost in the SpannerConnectionStringBuilder(string, ChannelCredential, SessionPoolManager) constructor.

We should be consistent and document the reasoning.

@jskeet jskeet added api: spanner Issues related to the Spanner API. type: cleanup An internal cleanup or hygiene concern. labels Sep 27, 2022
@jskeet jskeet self-assigned this Sep 27, 2022
@jskeet
Copy link
Collaborator Author

jskeet commented Sep 27, 2022

Looking at this again, we have a slight issue when setting ConnectionString, if the previous connection string specified conversion options but the new one doesn't. Here's a failing test:

[Fact]
public void SettingConnectionStringResetsConversionOptions()
{
    var builder = new SpannerConnectionStringBuilder();
    builder.ConnectionString = "SpannerToClrTypeDefaultMappings=DateToSpannerDate";
    builder.ConnectionString = "";
    Assert.Equal(SpannerConversionOptions.Default.DateToConfiguredClrType, builder.ConversionOptions.DateToConfiguredClrType);
}

Basically I suspect we want to create conversion options lazily, rather than responding to keys being set explicitly.

Will fix this.

@jskeet
Copy link
Collaborator Author

jskeet commented Sep 27, 2022

Ah - it's actually fairly straightforward; we just need to override Clear(), I think. That is always called when the ConnectionString property is set.

@jskeet jskeet added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Sep 27, 2022
@Rishabh-V
Copy link
Contributor

Hi @jskeet - This seems to have been introduced by me. I can take a look at it and make the changes after discussing it with you tomorrow. Please let me know.

@jskeet
Copy link
Collaborator Author

jskeet commented Sep 27, 2022

I've fixed it in a PR that I'll be sending later :)

jskeet added a commit to jskeet/google-cloud-dotnet that referenced this issue Sep 27, 2022
@jskeet jskeet closed this as completed in 92ba08b Sep 28, 2022
anshuldavid13 pushed a commit to anshuldavid13/google-cloud-dotnet that referenced this issue Oct 3, 2022
Rishabh-V added a commit to Rishabh-V/google-cloud-dotnet that referenced this issue Nov 3, 2022
Changes in Google.Cloud.Spanner.Data version 4.2.0:

### Bug fixes

- Fix SpannerConnectionStringBuilder.ConnectionString handling of conversion options. Fixes [issue 9158](googleapis#9158) ([commit 92ba08b](googleapis@92ba08b))

### New features

- Update transaction.proto to include different lock modes ([issue 9236](googleapis#9236)) ([commit 4fed510](googleapis@4fed510))
- Add support for FGAC  in Spanner ([commit 4e7eddb](googleapis@4e7eddb))
- Update result_set.proto to return undeclared parameters in ExecuteSql API ([commit cb86746](googleapis@cb86746))
- Support dependency injection of SpannerConnection ([commit f29a7f9](googleapis@f29a7f9))
- Support custom GoogleCredential in SpannerConnectionStringBuilder/SpannerConnection ([commit 898d3b3](googleapis@898d3b3))
- Added support for JSONB type in the PostgreSQL dialect. Note that JSONB arrays are not supported server-side yet.

Packages in this release:
- Release Google.Cloud.Spanner.Admin.Database.V1 version 4.2.0
- Release Google.Cloud.Spanner.Admin.Instance.V1 version 4.2.0
- Release Google.Cloud.Spanner.Common.V1 version 4.2.0
- Release Google.Cloud.Spanner.Data version 4.2.0
- Release Google.Cloud.Spanner.V1 version 4.2.0
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. type: cleanup An internal cleanup or hygiene concern.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants