Repository navigation
Fix DeriveParameters for arrays, enums and composite types - #1740
Conversation
771b0e1 to
5174932
Compare
|
@Brar Works great so far ! |
roji
left a comment
There was a problem hiding this comment.
@Brar, finally had time to review - thanks for this PR. You can see some minor comments and some larger questions (e.g. should be actually derive SpecificType given that we're obsoleting it).
Note that I already have some work in progress, so it's possible I'll just merge and then continue based on your work.
There was a problem hiding this comment.
How about renaming this to PostgresCompositeField for brevity? Also, please move this underneath PostgresCompositeType, which is the main type in this file.
There was a problem hiding this comment.
The TypeOID is already exposed publicly via PostgresType.OID. This property is still necessary for the two-pass loading of the composite type definition, but I think it should be kept internal.
Note that in my work to expose richer information, the composite field contains a reference to its PostgresType, allowing user to perform full reflection on PostgreSQL composite types. But you can leave that one for me.
There was a problem hiding this comment.
Note that in my implementation composite fields are loaded eagerly, so there's no real need for this Lazy. But leave it as-is, I will make the proper changes later.
There was a problem hiding this comment.
Thanks, good improvement on exception handling
There was a problem hiding this comment.
Please inverse the check. This would remove a level of nesting from the main code of the method.
There was a problem hiding this comment.
We indeed want all the parameter's properties to be set to the right values. However, a few comments:
- As we are obsoleting SpecificType in 3.3, I don't think we should go through the effort of deriving it.
- Note the way things work between NpgsqlDbType and DbType - setting one also sets the other. I think the same logic should be extended. In other words, in this piece of code we should simply set
PostgresType. Then, code in thePostgresTypesetter should make sure the other fields are set. In fact, I'm still hesitating on allowing users to setPostgresTypedirectly (and to haveTypeNameas a simply string-based shortcut which does the same thing).
There was a problem hiding this comment.
As written above, I don't think we should support deriving SpecificType, so most of this isn't needed. As it would make the whole method quite small some refactoring may be appropriate.
|
@roji given the fact that you are intending to change quite some functionality that this PR depends on, I'm not sure if it wouldn't be better to first merge your changes and after this, let me rebase my PR. |
|
@Brar as you prefer, I'll try to merge my work soon so you can rebase, hope it won't be too much breakage for you. |
|
@Brar Can you help me to write a query that proves that |
@dmitry-a-morozov please have a look at the tests in my pull request especially |
|
Hello @roji and @Brar. I hope you guys enjoyed holiday season. |
|
@dmitry-a-morozov and @Brar, the composite and enum work is almost complete, I'll probably merge later today or tomorrow. |
|
@roji OK, then I'll try to rebase this PR this weekend and afterwards address the remaining comments from your review above. |
|
@Brar and @dmitry-a-morozov, have merged my work - please see these notes. Note that I haven't yet exposed information about enum and composite fields, that's planned quite soon in #1779 (@Brar, I don't think you depend on this in any way, unlike @dmitry-a-morozov). |
5174932 to
36995b2
Compare
|
@roji I've updated the PR. |
|
Thanks @Brar, I'll try to find time as soon as possible to review. Am now working full time on Npgsql but there's a lot of other work going on. |
|
Hi @roji @Brar. |
|
@dmitry-a-morozov, I'd advise keeping a submodule reference to the git commit before the rebase until I get around to looking at things (just go into the submodule directory and do |
|
I don't follow your suggestion. |
|
@dmitry-a-morozov commits don't get rebased - only branches do. If you rewrite the history by rebasing, a new commit - with a new SHA1 - gets created, since the calculated SHA1 includes the reference to the parent commit (which is now different because we rebased...). I think that before the rebase this PR was on commit 51749324d261df7bfd69bb4787d07f4be903b4d7 (but I'm not sure, @Brar may be able to help). Try referencing that in your submodule. |
@dmitry-a-morozov what exactly is broken in https://github.com/Brar/npgsql/tree/FixDeriveOddParameterTypes ?
I'm asking because the branch itself shouldn't be broken. It builds on my machine and passes all tests as expected and so it should as a submodule on your machine unless I got something wrong. There's just some AppVeyor build oddity once again that prevents the AppVeyor build and by that also the generation of artifacts such as Nuget packages. |
|
@roji My understanding that git sub-module is always tied to particular commit. Anyway when I try to pull 5174932 I get |
|
@Brar My code relied on |
|
NpgsqlDbType.Enum is gone too? |
|
Yes, All this complicated setup makes no sense - it's much better to simply specify the PostgreSQL type as a string (via |
|
Got it. Make sense. |
|
If you're deriving parameters with @Brar's new feature, I think the idea is to also derive the Npgsql already contains a type hierarchy for describing PostgreSQL types, in the Npgsql.PostgresTypes namespace. These types inherit from So to answer your question, once @Brar completes his part, you should be able to check whether |
|
See @Brar comment above |
|
Ah, I didn't notice the comment. @Brar, I think it would be a good idea to at least have |
5151389 to
8d35b8a
Compare
bd697c4 to
dcdffa3
Compare
349e870 to
0fcf927
Compare
dcdffa3 to
9bfa2b7
Compare
|
Rebased and fixed some minor issues as it didn't apply properly after fixing #1779 |
|
As I see it the failing test Npgsql.Tests.SystemTransactionTests.CloseConnection() is rather a consequence of the rebase than something that has to do with the code changed by this PR. |
|
Thanks @Brar, the |
9bfa2b7 to
eca83c8
Compare
|
Rebased once again to make sure everything works after be9caf5 |
|
I start wondering when the AppVeyor build will ever not fail :-( |
|
Yeah, it's really quite frustrating - Keeping the builds working is a lot of work and I've been neglecting it lately. If Travis works I'm generally happy. |
roji
left a comment
There was a problem hiding this comment.
Finally got around to this :)
Looks pretty good, there's mainly a factoring issue (and a small correctness issue) around GetTypeInfoByOid/TryGetTypeInfoFromMapping.
I should be available and very reactive in the next few days so let's try to get this merged soon.
There was a problem hiding this comment.
I'd rather GetTypeInfoByOid() didn't return dataTypeName, which can simply be accessed on postgresType. At least in theory that method is generic, and the name is useful only in this specific context of parameter derivation. It would also simplify GetTypeInfoByOid() and make clear exactly what the dataTypeName is and where its coming from (i.e. that it's just a property on the postgresType.
There was a problem hiding this comment.
Maybe make this more explicit, explaining derivation in a few words and referencing CommandBuilder with <see .../> etc. pg_type probably doesn't mean a lot to most people.
There was a problem hiding this comment.
Extended the comment as suggested.
There was a problem hiding this comment.
As mentioned above, am not clear on this... It seems it will throw for PG types that have a mapping, but no NpgsqlDbType, and that aren't enum/composite. For one thing, this will be the case of any mappings added via the new external plugin API, since NpgsqlDbType cannot be updated. In other word, it's totally fine for a mapping to not have an NpgsqlDbType - we can still send parameters by populating DataTypeName. Even if this weren't the case, these methods aren't necessarily for use only by parameter derivation (even if they currently are) - there's no reason to limit them by throwing an exception if no NpgsqlDbType is found.
There was a problem hiding this comment.
I'd recommend simplifying this and maybe changing the relationship between the two methods (TryGetTypeInfoFromMapping and GetTypeInfoByOid):
- Enum/Composite is spread across the two:
TryGetTypeInfoFromMappingchecks for the factory type and returns true+null, which then makesGetTypeInfoByOidgo ahead and check forPostgres{Enum,Composite}Type. - NpgsqlDbType is determined by
TryGetTypeInfoFromMapping, except for the array case where it's constructed byGetTypeInfoByOid. - See comment below - the assumption seems to be that we can handle types with NpgsqlDbType and enums/composites, but other types without NpgsqlDbType aren't handled (exception thrown). I don't think this is correct - it's perfectly fine for mappings to not have an NpgsqlDbType (external plugins). Once NpgsqlDbType becomes optional, I think these two methods may change enough to warrant refactoring them into one method - but not sure.
typehere is an ambiguous name, should benpgsqlDbType
Do you want to take another look at this? I can also try to come up with a proposal if you want.
There was a problem hiding this comment.
Agreed and fixed.
TryGetTypeInfoFromMapping is now a tiny local helper function TryGetMapping
There was a problem hiding this comment.
Probably rename this test to DeriveFunctionParametersVarious?
There was a problem hiding this comment.
Agreed.
I took the opportunity to homogenize all the test names and added one more test that documents the currently non-working behavior of parameters that are arrays of composite types.
|
BTW, @Brar, I tried adding you as a contributor to the github project (to be able to assign you and stuff like that), but the invitation is still listed as pending. Did you receive it, would you like me to resend? If you don't want this of course let me know. |
|
@roji regarding the invitation: I can't remember getting any kind of notification and didn't see any hint in my GitHub profile or any other page I visit regularly. Anyways, this brougt me to actively search for the invitation and I finally found the hint on the Npgsql project page. I'll try to work through your comments today and address them accordingly. |
|
@Brar ok great, I can see you in the contributors team now. |
eca83c8 to
16f039e
Compare
|
@roji I agree with all your comments above and tried to modify the code accordingly. |
|
OK great, thanks for the contribution @Brar! |
This should fix #1736