Skip to content

Add NpgsqlDataSource.ReloadTypes{Async}#5919

Merged
roji merged 1 commit into
npgsql:mainfrom
manandre:data-source-reload-types
Nov 10, 2024
Merged

Add NpgsqlDataSource.ReloadTypes{Async}#5919
roji merged 1 commit into
npgsql:mainfrom
manandre:data-source-reload-types

Conversation

@manandre

@manandre manandre commented Nov 9, 2024

Copy link
Copy Markdown
Collaborator

Fixes #5905

@manandre
manandre force-pushed the data-source-reload-types branch from 7ae26f7 to 8544c7c Compare November 9, 2024 21:16

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @manandre, looks good overall! Can you please take a look at the comments?

.NET 9.0 is coming out on Tuesday, and we'll likely want to release Npgsql 9.0 very soon afterwards. So if you don't have time to quickly fix these comments, let me know and I'll take over this and complete it.

Comment thread test/Npgsql.Tests/DataSourceTests.cs Outdated
}

[Test]
public async Task ReloadTypesAsync()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test can be merged with the above, to exercise both sync and async in the same test (with a [Values] bool async parameter). Note that the only thing that needs to differ between the two tests is the invocation of ReloadTypes() vs. ReloadTypesAsync() - the rest of the code (e.g. the ExecuteScalarAsync()) can be async for both cases (that's not what we're testing here).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Tests merged

Comment thread test/Npgsql.Tests/DataSourceTests.cs
Comment thread test/Npgsql.Tests/DataSourceTests.cs Outdated
Assert.DoesNotThrowAsync(async () => await connection2.ExecuteScalarAsync($"SELECT 'happy'::{type}"));
}

private NpgsqlDataSource CreateDataSourceWithType(string type)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd personally just inline this, doesn't seem worth it for 3 lines

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OK

Comment thread test/Npgsql.Tests/TestUtil.cs Outdated
Unpooled
}

enum Mood { Sad, Ok, Happy }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd rather we kept this in the specific test classes rather than making it available in all classes, even if it's a bit of duplication...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed

Comment thread src/Npgsql/NpgsqlDataSource.cs Outdated
/// Flushes the type cache for this data source.
/// Type changes will appear for connections only after they are re-opened from the pool.
/// </summary>
public async Task ReloadTypesAsync()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is missing a CancellationToken parameter; I can see that the NpgsqlConnection.ReloadTypesAsync() overload is similarly missing it, I'm not sure why - maybe add it there as well as part of this PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @manandre!

Comment thread src/Npgsql/PublicAPI.Shipped.txt Outdated
Npgsql.NpgsqlConnection.ProvidePasswordCallback.set -> void
Npgsql.NpgsqlConnection.ReloadTypes() -> void
Npgsql.NpgsqlConnection.ReloadTypesAsync() -> System.Threading.Tasks.Task!
Npgsql.NpgsqlConnection.ReloadTypesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is technically incorrect: the "Shipped" file shouldn't ever get modified (it represents the current release, 8.0) - I'll take care of it.

@roji
roji force-pushed the data-source-reload-types branch from a41623a to 2986ecd Compare November 10, 2024 13:07
@roji
roji enabled auto-merge (squash) November 10, 2024 13:07
@roji
roji merged commit 7ef908d into npgsql:main Nov 10, 2024
@manandre
manandre deleted the data-source-reload-types branch November 10, 2024 13:18
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.

Add NpgsqlDataSource.ReloadTypes()

2 participants