-
Notifications
You must be signed in to change notification settings - Fork 162
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
Mapping of null values broken since 3.2.4 #748
Comments
Hi @nioertel I'd love to see your fix. Thansk for being so understandable… We have polished the |
Never mind, I have a reproducer…
Please share your approach… I think it should go into the right direction judging from your comment. We have some other fixes piling up, so we can wrap this up here in a 3.2.7 release this week. |
WDYT about that approach:
We have to keep the logic separate, but we can be more clear about it:
|
Use null instead of an empty list when the target isn’t a collection as well.
Thanks. I think the fix broke a functionality that made the mapping of invalid query results fail before. I added a review comment to the commit. Please check. |
Could you add a test for it? That's green before and red after my fix? Btw are you on the community slack? https://neo4j-users-slack-invite.herokuapp.com/ Maybe we can have a quick chat about it… The |
This test should do it:
|
Added and pushed an additional commit. Let's see what CI says. |
Use null instead of an empty list when the target isn’t a collection as well. This verifies the indirect illegal argument exception in case target property and query won’t fit but keeps the lenient behaviour in place when a query returning collections actually returns single valued collections. The scopes of the logback dependencies have been clarified. Thanks to @nioertel for reporting the issue and helping to solve it. This fixes #748.
I'm executing a query that returns combinations of String properties and a nodes.
E.g. MATCH (m:Movie) OPTIONAL MATCH (m)<-[:ACTS_IN]-(a:Actor) RETURN m.name AS name, a AS actor
The result of the query is mapped to a List of @QueryResult containing String name and Actor actor. Actor is defined as @NodeEntity.
For the movies which have no actors assigned the query returns combination "some movie", null.
Since OGM 3.2.4 an IllegalArgumentExeption is thrown by OGM as SingleUseEntityMapper#mapKnownNestedClasses returns Collections.emptyList() instead of null.
The issue was likely introduced with this commit c4d3046
Expected Behavior
The mapping should work in any case no matter if there are actors in the movie or not.
Current Behavior
The mapping fails with an IllegalArgumentException.
Possible Solution
The easy fix would be to replace mappedValue = Collections.emptyList(); by mappedValue = null; in line 188.
However I think the split of logic between writeProperty and mapKnownNestedClasses is not clear & clean. There is already some special logic for mapping collections in mapKnownNestedClasses and then again in writeProperty. This should be cleaned up as part of the fix.
I have the fix ready locally. If you confirm this is the right approach, I can prepare a pull request.
Your Environment
PS: It would be great to get a 3.2.7 release containing the fix before the end of this week if possible.
The text was updated successfully, but these errors were encountered: