Repository navigation
[Tests] Remove npgsqldbtype passing and rename related flag - #6305
Conversation
roji
left a comment
There was a problem hiding this comment.
LGTM.
There's a part of me that thinks it makes sense to continue to explicitly test both NpgsqlDbType and DataTypeName, even if we're committed to keeping the two fully synced forever... For one thing, it's not a bad idea to just ensure that things work, plus this documents the NpgsqlDbType for each type in the tests. I'm guessing that for extension types which don't have an NpgsqlDbType there can be an easy workaround for passing null or whatever, if that's the main reason behind this.
But I'm also OK with removing this if you prefer, no problem.
On that note, just want to make sure we do have at least minimum coverage for NpgsqlDbType functionality (these tests wouldn't need to be per-type, just to make sure that we stuff around NpgsqlDbType does work).
We still test the values during asserts, using the datatypename to npgsqldbtype map directly to produce the expected value. See https://github.com/npgsql/npgsql/pull/6305/files#diff-17ba1e1487416301d64375843c2c2f1def93042708fbde144b0d293e7e118d2eR260 This does mean changes in the map are authoritative for the tests also; so it doesn't catch incorrect changes to this static map (it's not what the type mapping asserts are meant to catch). If you think we should have a separate test to validate each entry in the map is what we expect, we could do so... IMO it's already the case that any changes to the map must come with sufficient scrutiny. Having, basically, a copy of this map in the tests won't add much to alert us something is wrong if we didn't catch the issue for the actual map either. |
|
OK I see, so we're covering just as much as before, just deriving the NpgsqlDbType from the DataTypeName instead of specifying it manually in the test, right. Am OK with this change, no problem. |
96d7a88 to
c38898c
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the type mapping test infrastructure by removing the npgsqlDbType parameter from AssertType methods and deriving it internally from the pgTypeName parameter instead. Additionally, it renames the isNpgsqlDbTypeInferredFromClrType parameter to isDataTypeInferredFromValue for better clarity.
Key changes:
- Removed
npgsqlDbTypeparameter from allAssertTypemethod signatures and call sites - Added derivation logic in
TestBase.csusingDataTypeName.FromDisplayName(pgTypeName).ToNpgsqlDbType() - Renamed
isNpgsqlDbTypeInferredFromClrTypetoisDataTypeInferredFromValuethroughout the codebase
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/Npgsql.Tests/Support/TestBase.cs | Core infrastructure changes - removed npgsqlDbType parameter from AssertType methods, added Npgsql.Internal.Postgres import, and now derives NpgsqlDbType internally from pgTypeName |
| test/Npgsql.Tests/Types/*.cs | Updated all test method calls to remove npgsqlDbType argument and renamed isNpgsqlDbTypeInferredFromClrType to isDataTypeInferredFromValue |
| test/Npgsql.Tests/Types/JsonTests.cs | Refactored test fixture to use string-based dataTypeName instead of NpgsqlDbType enum, removed unused import |
| test/Npgsql.Tests/Types/JsonDynamicTests.cs | Similar refactoring to use string-based dataTypeName instead of NpgsqlDbType enum |
| test/Npgsql.Tests/GlobalTypeMapperTests.cs | Updated AssertType calls with renamed parameter |
| test/Npgsql.Tests/CommandParameterTests.cs | Updated AssertTypeWrite calls with renamed parameter |
| test/Npgsql.PluginTests/*.cs | Updated all plugin test calls to remove npgsqlDbType parameter and use renamed flag |
The changes are consistent, well-executed, and align with the stated goal of simplifying the test infrastructure by deriving the NpgsqlDbType from the PostgreSQL type name rather than passing it as a redundant parameter.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
And derive it from our static map # Conflicts: # test/Npgsql.Tests/Support/TestBase.cs
…qlDbTypeInferredFromClrType: false
As we no longer directly pass NpgsqlDbType arguments
29c29ec to
06a92ec
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 33 out of 33 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…metry (#347) Updated [Npgsql.EntityFrameworkCore.PostgreSQL](https://github.com/npgsql/efcore.pg) from 10.0.3 to 10.0.4. <details> <summary>Release notes</summary> _Sourced from [Npgsql.EntityFrameworkCore.PostgreSQL's releases](https://github.com/npgsql/efcore.pg/releases)._ ## 10.0.4 [Milestone issue](https://github.com/npgsql/efcore.pg/milestone/79?closed=1) ## What's Changed * [10.0] Backport regex operand parentheses fix by @roji in npgsql/efcore.pg#3928 * [10.0] Remove unused SSL setup from Windows CI by @roji in npgsql/efcore.pg#3931 * [10.0] Backport unnest type mapping inference fix by @roji in npgsql/efcore.pg#3945 * [10.0] Truncate sub-microsecond ticks when formatting TimeSpan as interval by @roji in npgsql/efcore.pg#3947 * [10.0] Preserve row value type mappings when rewriting expressions by @roji in npgsql/efcore.pg#3954 * [10.0] Fix Last() on primitive collections returning the first array element by @roji in npgsql/efcore.pg#3956 * [10.0] Configure row value regression tuple mapping locally by @roji in npgsql/efcore.pg#3960 * [10.0] Update EF Core and other dependencies by @roji in npgsql/efcore.pg#3963 * [10.0] Fix collection conversion with nullable element converters (#3965) by @roji in npgsql/efcore.pg#3967 * [10.0] Fix Contains on an object collection over a value-converted column (#3961) by @roji in npgsql/efcore.pg#3970 * [10.0] Fix tsvector metadata cast for IReadOnlyList by @roji in npgsql/efcore.pg#3986 * [10.0] Fix explicit column types for owned JSON collections by @roji in npgsql/efcore.pg#3989 * [10.0] Prevent PadLeft/PadRight from truncating shorter target widths by @roji in npgsql/efcore.pg#3993 * [10.0] Fix array type inference for mixed collection types by @roji in npgsql/efcore.pg#3996 * [10.0] Fix null checks on unbounded NodaTime Interval bounds by @roji in npgsql/efcore.pg#4002 * [10.0] Backport fix for null propagation in date/time intervals by @roji in npgsql/efcore.pg#4015 * [10.0] Support System.Text.Json serialization of LTree by @roji in npgsql/efcore.pg#4010 * [10.0] Preserve array element converters with explicit column types by @roji in npgsql/efcore.pg#4011 * [10.0] Fix repeated seed-data updates for list properties by @roji in npgsql/efcore.pg#4029 * [10.0] Fix BCE NodaTime SQL literal formatting by @roji in npgsql/efcore.pg#4027 * [10.0] Preserve inherited HiLo sequences in model snapshots by @roji in npgsql/efcore.pg#4032 * [10.0] Fix date/time mapping round-tripping and cloning by @roji in npgsql/efcore.pg#4037 * [10.0] Fix Regex.Replace to replace all matches by @roji in npgsql/efcore.pg#4041 * [10.0] Restore raw JSON byte array mapping by @roji in npgsql/efcore.pg#4044 * [10.0] Translate ToString() on string expressions by @roji in npgsql/efcore.pg#4050 * [10.0] Own newly cloned connections by @roji in npgsql/efcore.pg#4056 * [10.0] Fix type mapping for derived tsquery parameters by @roji in npgsql/efcore.pg#4060 * [10.0] Fix precision-only numeric migration snapshot churn by @roji in npgsql/efcore.pg#4070 * [10.0] Fix byte-array projections from JSON collections by @roji in npgsql/efcore.pg#4073 * [10.0] Fix tsvector columns over JSON-mapped navigations/complex properties by @roji in npgsql/efcore.pg#4076 * [10.0] Fix hstore SQL literal generation for null and escaped values by @roji in npgsql/efcore.pg#4106 * [10.0] Fix TimeOnly.IsBetween for midnight-spanning ranges by @roji in npgsql/efcore.pg#4131 * [10.0] Parenthesize the item of ANY/ALL when its precedence requires it by @roji in npgsql/efcore.pg#4132 * [10.0] Format storage parameter values with the invariant culture by @roji in npgsql/efcore.pg#4133 **Full Changelog**: npgsql/efcore.pg@v10.0.3...v10.0.4 Commits viewable in [compare view](npgsql/efcore.pg@v10.0.3...v10.0.4). </details> Pinned [Npgsql.OpenTelemetry](https://github.com/npgsql/npgsql) at 11.0.0. <details> <summary>Release notes</summary> _Sourced from [Npgsql.OpenTelemetry's releases](https://github.com/npgsql/npgsql/releases)._ ## 11.0.0 See the [release notes](https://www.npgsql.org/doc/release-notes/11.0.html). The full list of changes is available [here](https://github.com/npgsql/npgsql/milestone/132?closed=1). ## What's Changed * Bump GitHubActionsTestLogger from 2.4.1 to 3.0.1 by @dependabot[bot] in npgsql/npgsql#6353 * Docs: clarify NpgsqlParameterCollection.Add(object) requires NpgsqlParameter by @nimanikoo in npgsql/npgsql#6342 * Bump actions/setup-dotnet from 5.0.0 to 5.0.1 by @dependabot[bot] in npgsql/npgsql#6355 * Bump Scriban.Signed from 6.5.1 to 6.5.2 by @dependabot[bot] in npgsql/npgsql#6356 * Fix flaky test PostgresType by @vonzshik in npgsql/npgsql#6354 * Drop net8.0 and net9.0 TFMs by @roji in npgsql/npgsql#6358 * Bump BenchmarkDotNet from 0.15.6 to 0.15.8 by @dependabot[bot] in npgsql/npgsql#6361 * Bump NUnit3TestAdapter from 5.2.0 to 6.0.0 by @dependabot[bot] in npgsql/npgsql#6365 * Throw OperationCancelledException with correct CancellationToken from Dns.GetHostAddressesAsync by @vonzshik in npgsql/npgsql#6364 * Bump dotnet logging and DI dependencies by @roji in npgsql/npgsql#6371 * Bump NodaTime from 3.2.2 to 3.2.3 by @dependabot[bot] in npgsql/npgsql#6375 * Bump actions/upload-artifact from 5 to 6 by @dependabot[bot] in npgsql/npgsql#6377 * Bump actions/cache from 4 to 5 by @dependabot[bot] in npgsql/npgsql#6378 * For COPY operations treat 0 as infinite timeout in addition to -1 by @vonzshik in npgsql/npgsql#6352 * Bump NUnit3TestAdapter from 6.0.0 to 6.0.1 by @dependabot[bot] in npgsql/npgsql#6387 * Fix reading numerics as BigInteger by @vonzshik in npgsql/npgsql#6385 * Add empty permissions block in Github Actions configs (#3694) by @roji in npgsql/npgsql#6392 * Fix test timeout_during_authentication by @vonzshik in npgsql/npgsql#6388 * Fix retrieving sequence file for hanging tests by @vonzshik in npgsql/npgsql#6397 * Fix reading BigInteger with composites by @vonzshik in npgsql/npgsql#6390 * Do not include password in data source name with Persist Security Info=true by @roji in npgsql/npgsql#6395 * [Tests] Remove npgsqldbtype passing and rename related flag by @NinoFloris in npgsql/npgsql#6305 * Year++ by @vonzshik in npgsql/npgsql#6402 * Bump NodaTime from 3.2.3 to 3.3.0 by @dependabot[bot] in npgsql/npgsql#6403 * Bump NUnit3TestAdapter from 6.0.1 to 6.1.0 by @dependabot[bot] in npgsql/npgsql#6405 * Bump some dependencies by @roji in npgsql/npgsql#6411 * Bump actions/setup-dotnet from 5.0.1 to 5.1.0 by @dependabot[bot] in npgsql/npgsql#6412 * Bump Microsoft.Data.SqlClient from 6.1.3 to 6.1.4 by @dependabot[bot] in npgsql/npgsql#6414 * Bump OpenTelemetry.Api from 1.14.0 to 1.15.0 by @dependabot[bot] in npgsql/npgsql#6420 * Bump OpenTelemetry and OpenTelemetry.Exporter.InMemory by @dependabot[bot] in npgsql/npgsql#6421 * Improve fallback handling for GSS session encryption when native library is missing by @vonzshik in npgsql/npgsql#6422 * Fix wrapping OperationCancelledException for physical open by @vonzshik in npgsql/npgsql#6425 * Fix reusing NpgsqlBatch with auto prepare by @vonzshik in npgsql/npgsql#6433 * Do not clear pool while establishing connection if we'll retry it by @vonzshik in npgsql/npgsql#6431 * Fix for retrieving column metadata for Postgres < 10 by @KeltorHD in npgsql/npgsql#6438 * Some SQL query cleanup by @roji in npgsql/npgsql#6439 * Reset connection when closing within TransactionScope by @roji in npgsql/npgsql#6424 * Fix per instance nullability converter resolver info code by @NinoFloris in npgsql/npgsql#6435 * Bump Microsoft.SourceLink.GitHub from 10.0.102 to 10.0.103 by @dependabot[bot] in npgsql/npgsql#6445 * Bump Microsoft.Extensions.DependencyInjection.Abstractions from 10.0.2 to 10.0.3 by @dependabot[bot] in npgsql/npgsql#6441 * Bump extensions versions to 10.0.3 by @roji in npgsql/npgsql#6448 * Bump Scriban.Signed from 6.5.2 to 6.5.3 by @dependabot[bot] in npgsql/npgsql#6455 * [Tests] Fully rework type mapping assertion helpers by @NinoFloris in npgsql/npgsql#6314 * Bump Microsoft.NET.Test.Sdk from 18.0.1 to 18.3.0 by @dependabot[bot] in npgsql/npgsql#6460 * Bump actions/upload-artifact from 6 to 7 by @dependabot[bot] in npgsql/npgsql#6461 ... (truncated) ## 10.0.4 [Release milestone](https://github.com/npgsql/npgsql/milestone/139?closed=1) **Full Changelog**: npgsql/npgsql@v10.0.3...v10.0.4 Commits viewable in [compare view](npgsql/npgsql@v10.0.3...v11.0.0). </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rene Bentes Pinto <[email protected]>
This is the start of a restructuring of the type mapping asserts. Recently we ran into them being hard to grasp in the Cube PR, and in #6267 I had to wrangle them into a passable shape again as well for those changes to pass.
The first change I've pulled out removes
npgsqlDbTypeas a parameter on any of the AssertType methods. In the second commit all the callers are changed. With this change we're always deriving the expected NpgsqlDbType from the given pgTypeName. The asserts still check whether the NpgsqlDbType is returned back to us correctly on the db parameter. We're using this same static map in the actual parameter implementation, so all tests pass without further changes.There is just no good reason to keep this duplication around. In discussions around #6267 we have also concluded again that we don't want
NpgsqlDbType <-> DataTypeNamemappings to become overridable in any way so this seems like a good moment to do it.The last commit renames
isNpgsqlDbTypeInferredFromClrTypetoisDataTypeInferredFromValue, which should have been renamed sooner for clarity. Starting from the 8.0 converter refactor pgTypeName and npgsqlDbType are both affected by this flag already, as we use the same source for these. Also note that the name moves away from 'ClrType' to 'Value'. This aligns the name with thevalueparameter, and captures that the db parameter might do value-dependent inference as well.My next PR should replace isDefault (isDefaultForWriting/isDefaultForReading) with parameters that more closely match what observations we do. It's too easy today to pass
isNpgsqlDbTypeInferredFromClrType: falseorisDefault: falsewhile in fact the test can (and should) run with more inference checks. Replacing the wider flags (so far, with a similar number of new ones) will allow us to do more inference checks, which have locally already caught a good number of those liberally defined tests.