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

Can not update the @ManyToMany list using PUT [DATAREST-1027]

Open
#1,389 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

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

Description

SM opened DATAREST-1027 and commented

Hello,
if you look the simple test here below, you are able to POST @ManyToMany (groups) list but you can not update it using PUT, only the email is correctly updated:

import json

import requests

HEADERS_JSON = {'Content-Type': 'application/json'}

def printj(j):
    print(json.dumps(j, indent=4))

def test_all():
    requests.post('http://localhost:8080/groups', headers=HEADERS_JSON, data='{"name":"Admins"}')
    requests.post('http://localhost:8080/groups', headers=HEADERS_JSON, data='{"name":"Testers"}')

    rj = requests.get('http://localhost:8080/groups/').json()
    groups = rj['_embedded']['groups']

    groups_hrefs = []
    for group in groups:
        groups_hrefs.append(group['_links']['group']['href'])

    user_json = {
        "email": "fb@example.com",
        "firstName": "Frodo",
        "lastName": "Baggins",
        "groups": groups_hrefs
    }

    rj = requests.post('http://localhost:8080/users', headers=HEADERS_JSON, data=json.dumps(user_json)).json()
    user_href = rj['_links']['user']['href']

1. UPDATE

    user_json = {
        "email": "fb2@example.com",
        "firstName": "Frodo",
        "lastName": "Baggins",
        "groups": groups_hrefs[:-1]
    }

    r = requests.put(user_href, headers=HEADERS_JSON, data=json.dumps(user_json))
    print r.text


if __name__ == '__main__':
    test_all()
// Generated file
package com.github.rognoni.generated.entities;

import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.ManyToMany;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "dry_user")
public class User {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Column(nullable=false)
	private String email;
	private String firstName;
	private String lastName;
	private String username;
	private String password;
	private Boolean isActive;
	private Boolean isStaff;
	private Boolean isSuperuser;
	private Date dateJoined;
	private Date lastLogin;
	@ManyToMany
	private List<Group> groups;
	@ManyToMany
	private List<Permission> permissions;

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Boolean getIsActive() {
		return isActive;
	}

	public void setIsActive(Boolean isActive) {
		this.isActive = isActive;
	}

	public Boolean getIsStaff() {
		return isStaff;
	}

	public void setIsStaff(Boolean isStaff) {
		this.isStaff = isStaff;
	}

	public Boolean getIsSuperuser() {
		return isSuperuser;
	}

	public void setIsSuperuser(Boolean isSuperuser) {
		this.isSuperuser = isSuperuser;
	}

	public Date getDateJoined() {
		return dateJoined;
	}

	public void setDateJoined(Date dateJoined) {
		this.dateJoined = dateJoined;
	}

	public Date getLastLogin() {
		return lastLogin;
	}

	public void setLastLogin(Date lastLogin) {
		this.lastLogin = lastLogin;
	}

	public List<Group> getGroups() {
		return groups;
	}

	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}

	public List<Permission> getPermissions() {
		return permissions;
	}

	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}
}

No further details from DATAREST-1027

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.