-
Notifications
You must be signed in to change notification settings - Fork 934
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
Conversation
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. |
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? |
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.
I would call it |
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. |
Yes let's try to make it strict. I wonder if it breaks anything in our tests. |
@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. |
Code looks correct-ish, so I approved. Yes, I've read the discussion. |
@bahusoid 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 |
There was a problem hiding this 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?)
…hibernate#2456) Co-authored-by: Roman Artiukhin <bahusdrive@gmail.com>
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.