You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If there is class with an optional ManyToOne property, setting the corresponding field of an existing record to null/0/empty returns a 400 - Bad Request, with error message: ""Expected IRI or nested document for attribute \u0022foobar\u0022, \u0022string\u0022 given."
This happens because the admin panel sends an empty string instead of a null value.
STR:
2 classes:
class A {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="B", inversedBy="foos")
*/
public $foobar;
public function getId(): int { return $this->id; }
}
class B
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="A", mappedBy="foobar")
*/
public $foos;
public function __construct() { $this->foos = new ArrayCollection(); }
public function getId(): int { return $this->id; }
}
create a record in B: curl 'http://localhost:8000/api/bs' --data '{}' -H 'content-type: application/ld+json'
create a record in A referring to the B's record: curl 'http://localhost:8000/api/as' --data '{"foobar":"/api/bs/XXX"}' -H 'content-type: application/ld+json'
update A's record from the admin panel:
Using the admin, deselect the field 'foobar' of the record /api/as/YYY and submit.
Expected results:
the A's record should have an empty 'foobar' relationship with class B.
If there is class with an optional ManyToOne property, setting the corresponding field of an existing record to null/0/empty returns a 400 - Bad Request, with error message: ""Expected IRI or nested document for attribute \u0022foobar\u0022, \u0022string\u0022 given."
This happens because the admin panel sends an empty string instead of a null value.
STR:
curl 'http://localhost:8000/api/bs' --data '{}' -H 'content-type: application/ld+json'
curl 'http://localhost:8000/api/as' --data '{"foobar":"/api/bs/XXX"}' -H 'content-type: application/ld+json'
Using the admin, deselect the field 'foobar' of the record /api/as/YYY and submit.
Expected results:
the A's record should have an empty 'foobar' relationship with class B.
Actual results:
400 Bad Request.
I suspect that the bug is in
convertReactAdminDataToHydraData
:https://github.com/api-platform/admin/blob/master/src/hydra/hydraClient.js#L123-L128
We should normalize the empty string value to a
null
.Here what I wrote to fix the issue locally:
The text was updated successfully, but these errors were encountered: