Skip to content

Commit

Permalink
Update the repro case & sample data to clarify v5.3.16 issue
Browse files Browse the repository at this point in the history
As requested in
  nhibernate/nhibernate-core#3609 (comment)
this expands the test case so that it fails in v5.3.16 as well as
5.3.17+.  It also adds some comments to the test pointing out
why it fails on 5.3.16, and why that's for a different reason to
the reason it fails in 5.3.17+.
  • Loading branch information
craigfowler committed Oct 29, 2024
1 parent fbbe38e commit c4bbf8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions NHibernate.PropertyRefBug.Tests/PropertyRefQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ public void QueryForDataWhichWasInsertedViaAdoUsingASubqueryShouldProvideExpecte
var validOrders = session.Query<Order>().Where(x => x.CreatedDate > new DateTime(2024, 9, 10));
var orderCount = session.Query<LineItem>().Count(x => validOrders.Any(y => y == x.Order));

// In v5.3.15 this test passes
//
// In v5.3.16 this test fails because it returns a result of 2 and not 1. That's occurred because the SQL WHERE generated for the EXISTS subquery is incorrect.
// It has entirely missed the criterion which relates LineItem to Order, so it's returning all line items without restriction.
// This failure reason for v5.3.16 seems to have been immediately fixed in v5.3.17, although it's still exhibiting the wrong behaviour in v5.3.17 (below).
//
// In v.5.3.17+ this test fails because it returns a result of 0 and not 1. That's occurred because the SQL WHERE generated for the EXISTS subquery is incorrect,
// in a different manner to the above. That's because it is trying to traverse the FK relationship using LineItem.OrderId and Order.Id, rather than
// LineItem.OrderId and Order.UniqueId.
Assert.That(orderCount, Is.EqualTo(1));
}

Expand Down
6 changes: 4 additions & 2 deletions NHibernate.PropertyRefBug/AdoDbInitialiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ Amount REAL NOT NULL

const string DataSql = @"
INSERT INTO TheOrder (Id, UniqueId, CreatedDate)
VALUES (1, '0ab92479-8a17-4dbc-9bef-ce4344940cec', '2024-09-19T12:10:00Z');
VALUES (1, '0ab92479-8a17-4dbc-9bef-ce4344940cec', '2024-09-19T12:10:00Z'),
(2, '4ca17d84-97aa-489f-8701-302a3879a388', '2021-09-19T12:20:00Z');
INSERT INTO LineItem(Id, OrderId, ItemName, Amount)
VALUES(1, '0ab92479-8a17-4dbc-9bef-ce4344940cec', 'Bananas', 5);";
VALUES(1, '0ab92479-8a17-4dbc-9bef-ce4344940cec', 'Bananas', 5),
(2, '4ca17d84-97aa-489f-8701-302a3879a388', 'Apples', 10);";

public static void CreateSchema(IDbConnection connection)
{
Expand Down

0 comments on commit c4bbf8e

Please sign in to comment.