spring-projects / spring-projects/spring-data-rest

The response handling when operating on the associated resource relationship seems incorrect?

Open
#2,495 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Jun 23, 2025.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Take the following Plan entity class as a demonstration:

@Data
@Entity
public class Plan {

    @Id
    @GeneratedValue
    private UUID id;

    private String name;

    @ManyToOne
    private Process process;

    @OneToMany
    private Set<PlanItem> items;

}

Single-association resource

When I try to request:
curl -v -X PUT http://127.0.0.1:8080/plans/{id}/process
or
curl -v -X PUT http://127.0.0.1:8080/plans/{id}/process -H "Content-Type: application/json"
or
curl -v -X PUT http://127.0.0.1:8080/plans/{id}/process -H "Content-Type: text/uri-list"

I got the exact same response:

*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080
* using HTTP/1.x
> PUT /plans/765b7c48-f0e1-402b-9bd1-74448fd1a93d/process HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/8.13.0
> Accept: */*
>
< HTTP/1.1 500
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Sat, 21 Jun 2025 20:22:55 GMT
< Connection: close
<
{"cause":null,"message":"Must send only 1 link to update a property reference that isn't a List or a Map."}* we are done reading and this is set to close, stop send
* abort upload
* shutting down connection #0

We got a 500 (Internal Server Error) response here, maybe it should have been 400 (Bad Request)?

For the case where "Content-Type" is not present or its value is not "text/uri-list", perhaps a "410 (Unsupported Media Type)" response would be better?


Multiple-association resources

When I PUT, POST, or PATCH a multi-relational resource (http://127.0.0.1:8080/plans/{id}/items) without a request body, whether there is no Content-Type header or Content-Type: application/json or Content-Type: text/uri-list, the response is always 204 (this phenomenon is also extremely deceptive.):

*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080
* using HTTP/1.x
> PUT /plans/765b7c48-f0e1-402b-9bd1-74448fd1a93d/items HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/8.13.0
> Accept: */*
>
< HTTP/1.1 204
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< Date: Sat, 21 Jun 2025 20:32:44 GMT
<
* Connection #0 to host 127.0.0.1 left intact

Should we also respond with 410 (Unsupported Media Type) when Content-Type does not exist or its value is not "text/uri-list"?

In addition, considering that the semantics of POST is to create new data, should the response be 400 (Bad Request) if the POST request does not carry a request body?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.