-
Notifications
You must be signed in to change notification settings - Fork 932
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
Inserting multiple associations of the same entity fails #3489
Inserting multiple associations of the same entity fails #3489
Conversation
@fredericDelaporte, I see that the "NHibernate (NHibernate Core)" check step in TeamCity is now failing as expected, for the contributed test. Is the merge just not possible in this case, e.g. can't really contribute failing tests? |
Need to mark the test with [KnownBug] attribute |
Thanks Alex for pointing that out! Added. |
Squashed and rebased on 5.4.x (11984a0), it does fail too. We should fix it on 5.4.x. As such, the test case needs to be rebased on 5.4.x and the PR needs to target the 5.4.x branch. For fixing it, I think the troubles lies within |
I have narrowed it to this change, but have not yet devise a proper fix. The above link points a comment in a long to load file in the review of the PR having introduced this change. Here is a direct link to current code involved in this bug: nhibernate-core/src/NHibernate/Hql/Ast/ANTLR/Tree/SelectClause.cs Lines 497 to 505 in d1790e7
At the second column, the from is already added, causing the execution to go into the else and not rendering the second column. In debug, forcing the execution to jump directly to RenderNonScalarIdentifiers (so, not adding again the from to combinedFromElements) allows the test to succeed. |
1df5de8
to
9265093
Compare
I have now overridden your branch in order to target 5.4.x for a potential fix I have added. |
Thanks much for identifying the root cause! |
@@ -494,7 +494,7 @@ private void InitAliases(List<ISelectExpression> selectExpressions) | |||
} | |||
|
|||
var node = (IASTNode) e; | |||
if (processedElements.Add(fromElement)) | |||
if (Walker.IsShallowQuery && node.Type == SqlGenerator.DOT || processedElements.Add(fromElement)) |
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.
The processedElements
set serves a de-duplication purpose of selected entities. But, alone, it fails accounting for associations selected in shallow queries which will be seen as having the same fromElement although being actually different entities being selected.
Shallow queries may still have duplicated entities selected and cannot be entirely ignored for the de-duplication, if we want to keep the test HqlDuplicateEntitySelectionSubQuery
as currently is. (I fail to understand why this tests is valid, why should we support the queries in this test, but I did not get answers about this here. And anyway, it has been release in 5.4, so, it is legacy.)
The DOT
check allows to recognize cases in shallow queries where the same fromElement may be used by different expressions selecting different things, and a such, needing to be not falsely de-duplicated.
(I thought about checking if the expressions e
where "the same" (having same Path) instead when sharing a common fromElement, but that would imply building a dictionary of sets instead of processedElements
. I do not consider it is worth it.)
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.
I fail to understand why this tests is valid, why should we support the queries in this test
To be honest, I don't remember why I've added such test. Looking back at it, I agree that the test shouldn't be added.
Perhaps we could add a TODO for removing test HqlDuplicateEntitySelectionSubQuery
in version 5.5
and remove the node.Type == SqlGenerator.DOT
part from the condition.
Hazzik and Maca, since the fix is actually from me, I will not approve this PR myself. |
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.
The fix looks good to me.
An dev package is available here. See also Nighlty builds for more instructions. @mihaicodrean, may you check this dev package solves the issue for your application, and that none other regression remains? |
Thanks for the fix! I have applied the patch to my local 5.5.0 branch, and all works as expected for me. |
This works in 5.3.3, for example, but not in 5.5.0.
Thoughts as to why / how to fix?
Here's the failing test message:
And the stack trace:
And the standard output: