Skip to content

Fix constant value in function cached in LINQ query #1540

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

Closed

Conversation

fredericDelaporte
Copy link
Member

@fredericDelaporte fredericDelaporte commented Jan 18, 2018

insideSelectClause = false;
break;
}
if (expression.Method.DeclaringType?.Namespace == "System.Linq")
Copy link
Member

@hazzik hazzik Jan 18, 2018

Choose a reason for hiding this comment

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

It should have else branch.

Copy link
Member Author

@fredericDelaporte fredericDelaporte Jan 19, 2018

Choose a reason for hiding this comment

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

For putting what in it? All the point of that if is to not alter insideSelectClause, considering that only System.Linq calls may represent an exit out of/entry in select clause.

Copy link
Member

Choose a reason for hiding this comment

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

To put insideSelectClause = false; as it is in the default branch of switch statement.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I've checked that my suggestion does not work.

@hazzik
Copy link
Member

hazzik commented Jan 19, 2018 via email

@fredericDelaporte
Copy link
Member Author

fredericDelaporte commented Jan 19, 2018

Can you add a test case to verify that assumption then?

Unless extending the LINQ query model with new custom clause extensions (things having a purpose similar to Queryable.Where), which Linq-2-NH does not do, I do not see what could prove this wrong.

Anyway, I have added a test on key generation with constants in a where.

@fredericDelaporte
Copy link
Member Author

If #1542 gets merged before this one, this one would be obsoleted and in need of being closed.

@hazzik
Copy link
Member

hazzik commented Jan 20, 2018

I have removed the .ToString overload requirements. This works by adding GetHashCode to the key.

Copy link
Member Author

@fredericDelaporte fredericDelaporte left a comment

Choose a reason for hiding this comment

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

This works by adding GetHashCode to the key.

This is not guaranteed unique. This will cause the bug to still sometimes occurs, but in a evading, very hard to diagnose way. For me, with this "fix", we should still override ToString for being safe. But users will have a very hard time discovering they need this, because the trouble will most likely never occurs during testing, will not be reproductible, and will bug their application occasionally, causing it to be unreliable due to this design in NHibernate.

I was thinking of using something like this but that would over-complicate the code. (And that would introduce a counter overflow possibility for long running applications, either blowing away or taking a (very tiny) risk of getting the bug back. Well, with a long counter, it would takes hundreds of millions years to occurs, assuming the app is not able of running on average more than one query per millisecond ; so with a long we could disregard this overflow risk.)

{
_string.Append(expression.Value);
_string.Append(value).Append("#").Append(value.GetHashCode()).Append(",");
Copy link
Member Author

Choose a reason for hiding this comment

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

I have a hard time conceiving a valid query having objects instances instead of primitive types in a list/array. Are you sure this is useful to change the enumerable case too?

@fredericDelaporte
Copy link
Member Author

Obsoleted by #1544.

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.

2 participants