Skip to content
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

Checking for possible composite converters in GraphEntityMapper.writeProperty #933

Merged

Conversation

oxisto
Copy link
Contributor

@oxisto oxisto commented Jan 25, 2023

This allows to resolve conflicts when a property is using a composite converter.

Fixes #932

Comment on lines 287 to 291
if (writer == null || writer.isComposite()) {
logger.debug("Unable to find property: {} on class: {} for writing", property.getKey(), classInfo.name());
} else {
Copy link
Collaborator

@meistermeier meistermeier Jan 25, 2023

Choose a reason for hiding this comment

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

Would really like to have a separate conditional branch with a dedicated message, maybe even more visible level, here.

Suggested change
if (writer == null || writer.isComposite()) {
logger.debug("Unable to find property: {} on class: {} for writing", property.getKey(), classInfo.name());
} else {
if (writer == null) {
logger.debug("Unable to find property: {} on class: {} for writing", property.getKey(), classInfo.name());
} else if (writer.isComposite()) {
logger.info("Property is already handled by a CompositeAttributeConverter"); // or similar wording

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that makes sense. Just FYI, for other properties that are handled by the CompositeAttributeConverter, which do not have the name conflict, the method gets also called and the writer is actually null. Therefore, the original debug message might also be misleading, but we can probably not differentiate between "somehow we could not find the property" and "property is already handled" in the first if.

@meistermeier
Copy link
Collaborator

Thanks for the PR, could you also provide a test case for this?
Something that maybe checks for the right log output like we do here

assertThat(loggerRule.getFormattedMessages()).areAtLeastOne(stringMatches);

(Please don't be irritated by the ..Rule naming ;) )

@oxisto
Copy link
Contributor Author

oxisto commented Jan 25, 2023

Thanks for the PR, could you also provide a test case for this? Something that maybe checks for the right log output like we do here

assertThat(loggerRule.getFormattedMessages()).areAtLeastOne(stringMatches);

(Please don't be irritated by the ..Rule naming ;) )

Sure, will do. Might need a little bit to find the proper test layout.

@oxisto
Copy link
Contributor Author

oxisto commented Jan 25, 2023

Unfortunately, I am a little lost with regards to tests @meistermeier. I can find tests for the SingleUseEntityMapper (which seems to have a similar problem), but not for the GraphEntityMapper

@meistermeier
Copy link
Collaborator

TBH the test suite is broad but unfortunately not well sorted. Something we have to address in the future (tried this once and dismissed it ;) )
For know, add the test to the PropertyTest in the integration test module, put your domain in the org/neo4j/ogm/domain/gh932 package and add it here:

sessionFactory = new SessionFactory(getDriver(), User.class.getName(), SomeNode.class.getName());

I will revisit it (or leave it there) before merge. Thanks for the effort.

@meistermeier
Copy link
Collaborator

Just saw your test commit: Just leave it as it is. Would also work for me.

@oxisto oxisto force-pushed the fix-composite-converter-field-name branch 2 times, most recently from 85a1ed1 to 9d59ed2 Compare January 25, 2023 18:54
@oxisto
Copy link
Contributor Author

oxisto commented Jan 25, 2023

TBH the test suite is broad but unfortunately not well sorted. Something we have to address in the future (tried this once and dismissed it ;) ) For know, add the test to the PropertyTest in the integration test module, put your domain in the org/neo4j/ogm/domain/gh932 package and add it here:

sessionFactory = new SessionFactory(getDriver(), User.class.getName(), SomeNode.class.getName());

I will revisit it (or leave it there) before merge. Thanks for the effort.

Ok I did that. The tests run successful on my machine. Fingers crossed for GitHub actions ;)

@oxisto oxisto marked this pull request as ready for review January 25, 2023 18:54
@meistermeier
Copy link
Collaborator

Locally this is already running perfectly fine. I would go ahead and merge this.
Could you please sign the CLA? https://neo4j.com/developer/cla/
I've put the log output check also in the test case, just to be sure that the new condition gets hit and not the writer==null.

@oxisto
Copy link
Contributor Author

oxisto commented Jan 27, 2023

Locally this is already running perfectly fine. I would go ahead and merge this.
Could you please sign the CLA? https://neo4j.com/developer/cla/
I've put the log output check also in the test case, just to be sure that the new condition gets hit and not the writer==null.

Done

…eProperty`

This allows to resolve conflicts when a property is using a composite converter.

Fixes neo4j#932
@meistermeier meistermeier force-pushed the fix-composite-converter-field-name branch from 9d59ed2 to 5166b5c Compare January 27, 2023 10:42
@meistermeier
Copy link
Collaborator

Thanks for signing and letting me push the changes on your branch.
This makes merging much nicer.

@meistermeier meistermeier merged commit 364c9a0 into neo4j:master Jan 27, 2023
@oxisto oxisto deleted the fix-composite-converter-field-name branch January 27, 2023 11:10
@oxisto
Copy link
Contributor Author

oxisto commented Jan 29, 2023

Thanks for signing and letting me push the changes on your branch.
This makes merging much nicer.

Excellent, thanks! Just wondering... Are you following a certain release schedule, e.g. every X months or are you basically releasing if enough PRs are merged? Looking forward to 4.0.2 ;)

@meistermeier
Copy link
Collaborator

...like this https://github.com/neo4j/neo4j-ogm/releases/tag/v4.0.2?
😺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use name of field converted with a CompositeAttributeConverter in converted map
2 participants