Skip to content

Test case for #1180 and improve NullableType.ToString #2456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 10, 2020

Conversation

delta-emil
Copy link
Contributor

@delta-emil delta-emil commented Jul 28, 2020

Test case for #1180

This allows comparing vague SqlTypes (without Length/Precision/Scale defined), which is what you get for constants, to always be considered equal to their more particular counterparts. Instead of only if they are on the left hand side of the comparison.

Also added an override of ToString for NullableType, so that type-related error messages, like the one in ConditionalProjection give useful information about types differing only by their SqlType.

@bahusoid
Copy link
Member

to always be considered equal to their more particular counterparts. Instead of only if they are on the left hand side of the comparison.

But why they should be considered equal? Should not they be always considered not equal on both sides of comparisons instead?

And for #1180 I think we should extend ctor to allow to provide return type explicitly.

@delta-emil
Copy link
Contributor Author

But why they should be considered equal? Should not they be always considered not equal on both sides of comparisons instead?

That is an interesting question. When I saw the comparison in SqlTypes's Equals, I assumed the intent was to allow a loose type to be equal to any of its stricter versions, but someone just forgot to make it symmetrical.

In the case of the ConstantProjection inside a ConditionalProjection, forcing the user to explicitly give provide the IType of the ConstantProjection or the ConditionalProjection, seems a bit like an unnecessary annoyance, when the value inferred by ConstantProjection internally calling NHibernateUtil.GuessType is good enough for the job.

It would definitely force me to do a lot more work in one particular use case, where I have code dynamically put together a query, but I'll deal with it, if the community feels that's the way to go. Probably by making a custom variation of ConditionalProjection for that place.

Another option would be to have a separate "LooseEquals" for cases like the ConditionalProjection comparing the types of its two result projections? Or maybe have ConditionalProjection only be a bit loose with the type comparison when a ConstantProjection is involved?

@bahusoid
Copy link
Member

forcing the user to explicitly give provide the IType of the ConstantProjection or the ConditionalProjection, seems a bit like an unnecessary annoyance,

I meant it as optional parameter. So user should provide it only in case of ambiguity. So I don't see it as much of annoyance.

Another option would be to have a separate "LooseEquals"

I would call it IsTypeCompatible or something like that. And IMO it requires additional thinking. To me it seems it's asymmetrical thing by nature - 10-length string is compatible with 1-length string for output parameter. But it's not true otherwise. And it's completely different story for input parameters. And if it's required only for this case I don't think it's worth to be implemented inside NHibernate.

@delta-emil
Copy link
Contributor Author

Shall I update the change to resolve the Equals asymmetry in the direction of strict checks? That will at least make things act consistently when swapping spots, and provide a better error message, when types don't strictly match.

Deciding on where to go with ConditionalProjection's GetTypes can maybe be done separately by someone with better understanding of when and how the IType and SqlType instances are used. After all, if #2460 gets merged, ConditionalProjection's GetTypes won't even get called in the case I came across. So I won't even know what test case to write.

@bahusoid
Copy link
Member

Shall I update the change to resolve the Equals asymmetry in the direction of strict checks?

Yes let's try to make it strict. I wonder if it breaks anything in our tests.

hazzik
hazzik previously approved these changes Aug 10, 2020
@bahusoid
Copy link
Member

@hazzik Why approved? Have you read the discussion? In current state this PR makes types with defined Length (or Precision or.. ) be always equal to type without defined Length. That's IMO not the right behavior - 1 length string type should not be equal to string type without length defined.

@hazzik
Copy link
Member

hazzik commented Aug 11, 2020

Code looks correct-ish, so I approved. Yes, I've read the discussion.

@hazzik hazzik self-requested a review August 11, 2020 00:25
@hazzik hazzik removed their request for review September 8, 2020 22:31
@hazzik
Copy link
Member

hazzik commented Sep 8, 2020

@bahusoid can you finialize this?

@bahusoid
Copy link
Member

bahusoid commented Sep 9, 2020

can you finialize this?

I think this PR can be committed only as unit tests. As suggested fix is incorrect and proper asymmetrical fix won't fix #1180

@bahusoid bahusoid changed the title #1180 fix asymmetrical SqlType comparison Test case for #1180 and improve NullableType.ToString Sep 10, 2020
Copy link
Member

@bahusoid bahusoid left a comment

Choose a reason for hiding this comment

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

Approve unit tests and better error message changes.

And it seems fix should implement "loosen" equality right inside ConditionalProjection (maybe just check that NullableType.ReturnedClass is the same?)

@hazzik hazzik merged commit 1fa50d9 into nhibernate:master Sep 10, 2020
@hazzik hazzik added this to the next minor milestone Sep 10, 2020
hazzik pushed a commit to delta-emil/nhibernate-core that referenced this pull request Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants