Skip to content

Regression on PATCH requests when dealing with OneToMany link #2287

@ddewaele

Description

@ddewaele

We noticed some regression in 4.1.1 on how on PATCH requests update OneToMany links on an entity.

Given an Invoice in the database containing only 1 invoiceLine, if I execute the following PATCH request to update this invoice (including 2 invoiceLines in the payload), the request will return a 200 but only 1 invoiceLine will be updated.

curl --location --request PATCH 'http://localhost:8080/invoices/19' \
--header 'Content-Type: application/json' \
--data-raw '{
    "reference":"124_update_patch",
    "invoiceLines": [
        {
            "name":"patch_prod1_update_patch",
            "quantity":10
        },
        {
            "name":"patch_prod2_update_patch",
            "quantity":20
        }
    ]
}'
@Entity
@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public class Invoice {

    @Id
    @GeneratedValue
    private Long id;

    private String reference;

    @OneToMany(fetch = LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "invoice_id")
    private Set<InvoiceLine> invoiceLines = new HashSet<>();


}
@Entity
@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public class InvoiceLine {

    @Id
    @GeneratedValue
    private Long id;

    private String name;

    private Integer quantity;

}

This is due to the following commit d6d8c50 for issue #2261

This worked fine in 4.1.0 as the break didn't occur there.

I noticed in the issue the following comment :

We now completely skip handling additional values as they don't need to be merged anyway.

Is this the semantics on how a PATCH should work with OneToManyCollections ?

I was under the impression that the PATCH method should update the invoiceLines accordingly, and we should end up with 2 invoicelines after this PATCH.

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions