-
Notifications
You must be signed in to change notification settings - Fork 934
Serilog causes collection initializing with zero rows after update to NH5 #1667
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
Comments
No idea. Try isolating your trouble into a test case, then I may be able to check what is going on. See there. |
According to log 0 records are loaded from DB. SELECT accountsit0_.AccountId AS accountid3_1_1_
,accountsit0_.EntityId AS entityid1_1_1_
,accountsit0_.EntityId AS entityid1_1_0_
,accountsit0_.Version AS version2_1_0_
,accountsit0_.AccountId AS accountid3_1_0_
,accountsit0_.Privileges AS privileges4_1_0_
,accountsit0_.SiteId AS siteid5_1_0_
,accountsit0_.CreatedById AS createdbyid6_1_0_
,accountsit0_.CreatedByName AS createdbyname7_1_0_
,accountsit0_.CreatedCoordinates AS createdcoordinates8_1_0_
,accountsit0_.CreatedDate AS createddate9_1_0_
,accountsit0_.CreatedLocation AS createdlocation10_1_0_
,accountsit0_.CreatedThreatLevel AS createdthreatlevel11_1_0_
,accountsit0_.IsActive AS isactive12_1_0_
,accountsit0_.ModifiedById AS modifiedbyid13_1_0_
,accountsit0_.ModifiedByName AS modifiedbyname14_1_0_
,accountsit0_.ModifiedCoordinates AS modifiedcoordinates15_1_0_
,accountsit0_.ModifiedDate AS modifieddate16_1_0_
,accountsit0_.ModifiedLocation AS modifiedlocation17_1_0_
,accountsit0_.ModifiedThreatLevel AS modifiedthreatlevel18_1_0_
FROM AccountSites accountsit0_
WHERE (accountsit0_.IsActive = 1)
AND accountsit0_.AccountId = '8736478d-fcff-4a35-ac44-cfdf426d83c1' If this query loads something then it seems something wrong with parameters setting logic. |
@bahusoid When I run the query manually I get 7 records. I'm going to try to generate a test case following the instructions from @fredericDelaporte. |
@jsmarcus are you using Serilog NH logging? I have the same issue (no child collections loaded) when using package NHibernate.Logging.Serilog. When I hack it and don't pass state.Args, the issue is gone. |
@gacu82 I wasn't using Serilog but was using the sample implementation of the NHibernateToMicrosoftLogger. It has a similar line which causes the problem. nhibernate-core/src/NHibernate.Example.Web/Infrastructure/NHibernateToMicrosoftLogger.cs Line 30 in 92de0b7
|
That is a finding! How a logger can corrupt loading? From what you have seen, is it a flaw on the NHibernate side or on the logger side? Anyway since the example logger triggers this too, a test case for reproducing this easily (then fixing either the logger or NHibernate) would still help. |
This is a 5.1 regression introduced by #1377. log.Debug("constructing collection load context for result set [{0}]", resultSet); Previously, it was: log.Debug("constructing collection load context for result set [" + resultSet + "]"); The change has been made to enable structured logging. Previous code was always just calling a "ToString()" on So enabling debug logs may wreck collection loading, depending on the used logger. But what should be done? Should it be considered as a flaw of Serilog, which should have more advanced logics for avoiding mutating logged objects? (Like detecting that the enumerable is a data reader and should not be enumerated...) Or is it a known bad practice to supply this kind of mutable objects to the logger, and this should be changed everywhere in NHibernate ? (For what? An explicit @ngbrown, any thoughts? |
Serilog has logic that clones a Replacing However, it appears the goal is actually to display the concrete type of the log.Debug("constructing collection load context for result set [{0}]", resultSet.GetType()); |
Loggers may enumerate them, causing them to reach their end before being actually used. Fix nhibernate#1667
Loggers may enumerate them, causing them to reach their end before being actually used. Fix #1667
@nhibernate/core NB: update the release notes with the new title. |
I have a lazy loaded collection that is not initializing properly after updating to NH5. From what I can tell I have everything configured correctly and I have not found any change notes that indicate I should be doing things differently in NH5 compared to 4. I have tried debugging and tracing what is going on but have reached the limits of what I can check unassisted.
Collection config
Many-to-one config
I have attached the log for the initialization of the collection. Please any direction to help track down the issue would be helpful.
Collection Initialization Log.txt
The text was updated successfully, but these errors were encountered: