Skip to content

Remove string connection string keys that have a default value - #6725

Open
johnkaram02 wants to merge 1 commit into
npgsql:mainfrom
johnkaram02:builder-remove-string-defaults
Open

johnkaram02 wants to merge 1 commit into
npgsql:mainfrom
johnkaram02:builder-remove-string-defaults

Conversation

@johnkaram02

Copy link
Copy Markdown

Fixes #

NpgsqlConnectionStringBuilder.Remove resets the property to its default value. For string properties it relies on the setter to remove the key, which only works when the default is null. Encoding and Kerberos Service Name default to UTF8 and postgres, so their setters wrote the key back. Remove("Encoding") left Encoding=UTF8 in the connection string, and Clear() left a builder with one key.

This change updates the source generator template so the generated Remove also removes the key from the base dictionary for string properties that have a default value. The properties still return their defaults after the key is removed.

The new Remove_string_property_with_default_value and Clear_string_property_with_default_value tests fail without the fix and pass with it. I ran ConnectionStringBuilderTests (13 passed), ConnectionTests (147 passed, 7 skipped) and DataSourceTests (34 passed) against PostgreSQL 17.11 on Linux with .NET SDK 10.0.403.

NpgsqlConnectionStringBuilder.Remove resets the property to its default
value, and for string properties relies on the setter to remove the key.
That only works when the default is null. Encoding and Kerberos Service
Name default to "UTF8" and "postgres", so their setters wrote the key
back: Remove("Encoding") left "Encoding=UTF8" in the connection string,
and Clear() left a builder with one key.

Also remove the key from the base dictionary for string properties that
have a default value.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant