Skip to content

Conversation

@bvulaj
Copy link

@bvulaj bvulaj commented Apr 1, 2019

Fix for the change:

-				if (source.getLinks().size() != 1) {
+				if (source.getLinks().hasSingleLink()) {

554d6cb#diff-1d7c16fe1992fef13a47fa8ab8599718L317

@pivotal-issuemaster
Copy link

@bvulaj Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@bvulaj Thank you for signing the Contributor License Agreement!

@bvulaj
Copy link
Author

bvulaj commented Jul 10, 2019

This is still a bug in 3.2 RC - any update on merging?

@lareferencia
Copy link

Sorry, but I am having problems with this issue.

Correct me if am wrong, but in line 321, the context is "check if is a single link since we are updating a property that is not a collection" so I think that the right line is

if ( ! source.getLinks().hasSingleLink() ) {
note the !

because the exception only must be throw if links is greater than 1

@gregturn
Copy link
Contributor

Is there a test case that illustrates this? We can't move forward on a single line change that flips on a "!".

@lareferencia
Copy link

Sorry, I just discovered a pull request with the same proposal waiting to be approved.

#364

@bvulaj
Copy link
Author

bvulaj commented Oct 10, 2019

#364 is a duplicate of this PR.

@luvarqpp
Copy link
Contributor

luvarqpp commented Oct 11, 2019

Try to have a look at git blame just before bug was introduced: https://github.com/spring-projects/spring-data-rest/blame/ce321da80715f9201a5fa12b4385264e3e861c31/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java#L317

To test this problem (I would write some, having a time to learn how to make some unit test instead of integration one):

  • prepare entity Comment with OneToOne association to User (createdBy association)
  • prepare User entity
  • try to associate some author to existing Comment

Sample code snippet for last step:

createCommentResponse = ...
userLink = ...

final String authorAssociationEndpoint = JsonPath.read(createCommentResponse.getResponseBody(), "$._links.createdBy.href");
log.info("Going to add single User to association endpoint for author (createdBy).");
        this.webClient.put().uri(authorAssociationEndpoint)
                .contentType(MediaType.valueOf("text/uri-list"))
                .accept(MediaTypes.HAL_JSON)
                .bodyValue(userLink)
                .exchange().expectStatus().value(is(204));

PS: If someone can point me to similar test, I will try to implement this one.

@lqforgithub
Copy link

if you are using spring boot 2.2.0.RELEASE, you'll have this bug. 2.1.4.RELEASE is fine.

@luvarqpp
Copy link
Contributor

Is there a test case that illustrates this? We can't move forward on a single line change that flips on a "!".

I have created two tests. One positive and one negative. It is in my version of pull request #364 to this bug.

@gregturn
Copy link
Contributor

gregturn commented Oct 21, 2019

Resolved via 202a8aa. Backported to 3.2.x via 87f9904.

Thanks everyone for working hard to bring this one home. I went ahead and used #364 as the final solution.

The solution is in both master branch (Neumann) as well as 3.2.x (Moore SR1).

@gregturn gregturn closed this Oct 21, 2019
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.

6 participants