Repository navigation
Update noda time plugin to support bcl types by forwarding these to the existing bcl type handlers. - #3124
Conversation
…he existing bcl type handlers. This is a temporary quick fix so that noda types can co-exist with bcl types until clean support for multiple type handlers will be implemented. See issue npgsql#2439 for details.
YohDeadfall
left a comment
There was a problem hiding this comment.
Thank you for submitting the fix! Let's do review now...
roji
left a comment
There was a problem hiding this comment.
Looks great, but see note about simplifying how the type handlers work.
|
Thanks guys for the feedback! I will push an update probably tomorrow. |
YohDeadfall
left a comment
There was a problem hiding this comment.
Much better, thanks! What you forgot to do is to register CLR types for time types in the UseNodaTime method.
I'll continue tomorrow. Also need to finish work on unit tests. |
Since a CLR Type can only be used in a single mapping, I am not sure wich CLR types you mean? |
|
Ok guys, I think I am done for now and this should be ready for final review.
Regarding the "InternalsVisibleTo" question: This is needed because BCL type handler Ctors/Methods are internal. Since i need to delegate to them, InternalsVisibleTo is needed. Hope its ok now. Please let me know if something is missing. |
|
|
||
| void INpgsqlSimpleTypeHandler<DateTime>.Write(DateTime value, NpgsqlWriteBuffer buf, NpgsqlParameter parameter) | ||
| => ((INpgsqlSimpleTypeHandler<DateTime>)_bclHandler).Write(value, buf, parameter); | ||
| } |
There was a problem hiding this comment.
You might be wondering why I have an explicit cast here. This is because there is an implicit conversion from DateTime to NpgsqlDateTime. Therforce c#s overload resolution always picks NpgsqlDateTime methods when invoking the BCL handler methods.
Overload resolution always picks the nearest overload in the inheritance hierarchy. Since ValidateAndGetLength(TPsv value, NpgsqlParameter? parameter) is defined one inheritance hierarchy above ValidateAndGetLength(TDefault value, NpgsqlParameter? parameter), the TPsv overload is picked by using the implicit operator defined in NpgsqlDateTime.
Since there is special handling for DateTime.MaxValue/MinValue (convertInfinityDateTime), this matters.
There was a problem hiding this comment.
Thanks for the explanation, another problematic aspect of the provider-specific types... We should consider removing the implicit cast operators (unless we remove the types entirely...)
|
One more thing: I resolved all previous discussions here to cleanup for the next round. Hope thats ok ;-) |
|
Question: Once this is merged, it probably makes sense to update noda time unit tests in "efcore.pg" accordingly? E.x. I would add CLR datetime types here: https://github.com/npgsql/efcore.pg/blob/dev/test/EFCore.PG.NodaTime.FunctionalTests/NodaTimeQueryNpgsqlTest.cs#L431 |
roji
left a comment
There was a problem hiding this comment.
Thanks, this looks great to me! See only the note about InternalsVisibleTo which I'd rather we avoided.
Once this is merged, it probably makes sense to update noda time unit tests in "efcore.pg" accordingly? E.x. I would add CLR datetime types here: https://github.com/npgsql/efcore.pg/blob/dev/test/EFCore.PG.NodaTime.FunctionalTests/NodaTimeQueryNpgsqlTest.cs#L431
Yeah, that's a good idea - but we'd have to make the EFCore.PG depend on a newer version of Npgsql for that to work. At some point I have to start doing this anyway - the upcoming EFCore.PG 5.0 should take a dependency on Npgsql 5.0, which we should release at the same time. So it would be good if you could open an issue for these tests.
|
|
||
| void INpgsqlSimpleTypeHandler<DateTime>.Write(DateTime value, NpgsqlWriteBuffer buf, NpgsqlParameter parameter) | ||
| => ((INpgsqlSimpleTypeHandler<DateTime>)_bclHandler).Write(value, buf, parameter); | ||
| } |
There was a problem hiding this comment.
Thanks for the explanation, another problematic aspect of the provider-specific types... We should consider removing the implicit cast operators (unless we remove the types entirely...)
| "7aa16153bcea2ae9a471145624826f60d7c8e71cd025b554a0177bd935a78096" + | ||
| "29f0a7afc778ebb4ad033e1bf512c1a9c6ceea26b077bc46cac93800435e77ee")] | ||
|
|
||
| [assembly: InternalsVisibleTo("Npgsql.NodaTime, PublicKey=" + |
There was a problem hiding this comment.
I think it's best to make these ctors/methods public rather than introducing IVT.
The type handlers are currently somewhat inconsistent with public/internal - we've made public certain things because we needed them, but not others. As a general rule, the type handers should be a sort of "public internal" (similar to how EF Core manages things): they should be public for easy extension, but without any guarantees against breaking changes (at least in the near future).
|
Ok, I have removed IVT and made the needed ctors and Read method public. |
|
@roji, should it be backported to 4.1.5? It breaks nothing, but relaxes restrictions and could make users happier. |
|
Thanks @davidroth! I'll look into getting the EF Core provider running on this so we can add tests etc. @YohDeadfall good point. We should usually try to do only bugfixes in patches, but I agree this is very low risk and seems to be causing issues to quite a few people. Backported via 64827fa. |
|
Thanks very much to you all for working on this - we have been blocked from using NodaTime with PG/EF until now, and every time we have a DateTime-related UTC vs Local screw-up I've longed for this to be sorted. Putting back it into 4.x is the cherry on top of the icing on top of the cake. |
This is a fix so that noda types can co-exist with bcl types until clean support for multiple type handlers will be implemented.
See issue #2439 for details.