Fix type mapping for non-public types - #4586
Conversation
roji
left a comment
There was a problem hiding this comment.
Looks good, thanks.
For a proper cleanup in 7.0, we should decide whether we want to allow resolver to know about schemas (see comment below).
- If we do, we can pass a QualifiedName struct (schema+name) to the resolver, and then resolvers which don't care (like the built-in one) can just match on the name.
- If we don't, then resolver should always get a non-qualified name (we can assert on it)
Here's a test for this which you can use as a starting point. Note that it also fails on other things (e.g. reading back the correct NpgsqlParameter.DataTypeName after setting NpgsqlDbType). If it's complicated to handle those, we can defer that to 7.0, it doesn't seem completely critical (and we need to get the main fix out).
[Test, IssueLink("https://github.com/npgsql/npgsql/issues/4582")]
public async Task Type_in_non_default_schema()
{
await using var conn = await OpenConnectionAsync();
await using var _ = await CreateTempSchema(conn, out var schema);
await conn.ExecuteNonQueryAsync($"DROP EXTENSION IF EXISTS citext; CREATE EXTENSION citext SCHEMA {schema}");
try
{
conn.ReloadTypes();
// await AssertType("foo", "foo", $"{schema}.citext", NpgsqlDbType.Citext, isDefaultForWriting: false, isDefaultForReading: false);
await AssertTypeRead("foo", "foo", $"{schema}.citext", isDefault: false);
}
finally
{
await conn.ExecuteNonQueryAsync("DROP EXTENSION citext");
}
}| lock (_writeLock) | ||
| { | ||
| if ((handler = ResolveByDataTypeName(pgType.SchemaQualifiedName, throwOnError: false)) is not null) | ||
| if ((handler = ResolveByDataTypeNameCore(pgType.FullName)) is not null) |
There was a problem hiding this comment.
I'm not sure we really need this - will a resolver ever know about a specific type in a specific schema? Maybe only some special user-written one, tailored for a specific scenario or something...
There was a problem hiding this comment.
We probably don't need this, but it's definitely a nice thing to support just in case (if we do go through with resolver cleanup in 7.0, we'll essentially going to support this anyway, just at resolver level, and not at TypeMapper).
There was a problem hiding this comment.
Yeah, and there's no perf impact either, so no reason to remove it.
roji
left a comment
There was a problem hiding this comment.
Only testing-related comments (possibly using AssertType and dropping the extension)
| lock (_writeLock) | ||
| { | ||
| if ((handler = ResolveByDataTypeName(pgType.SchemaQualifiedName, throwOnError: false)) is not null) | ||
| if ((handler = ResolveByDataTypeNameCore(pgType.FullName)) is not null) |
There was a problem hiding this comment.
Yeah, and there's no perf impact either, so no reason to remove it.
|
Backported to 6.0.6 via b3c4023 |
Fixes #4582