Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

standard_put: false Doesn't work for Embeddables #6914

Open
ostrolucky opened this issue Jan 13, 2025 · 4 comments
Open

standard_put: false Doesn't work for Embeddables #6914

ostrolucky opened this issue Jan 13, 2025 · 4 comments

Comments

@ostrolucky
Copy link
Contributor

API Platform version(s) affected: 4.0.14

Description
With standard_put: false, I expect that missing fields would not be reset to NULL. However, this is not true for Embeddables.

How to reproduce

#[ApiResource()]
#[ORM\Entity()
class DatasyncConnector {
    #[ORM\Embedded(Embeddable::class)]
    public ?Embeddable $embeddable = null;
}

#[ORM\Embeddable()]
class MicrosoftGraph
{
    #[ORM\Column(type: 'guid', nullable: true)]
    public string $clientId;
    #[ORM\Column(nullable: true)]
    public ?string $clientSecret = null;
}

If you send payload

{"embeddable": {"client_id": "foo", "client_secret": "bar"}}

And afterwards

{"embeddable": {"client_id": "foo"}}

client_secret would be set to NULL. Expectation is that client_secret would preserve previous value (bar).

Possible Solution

Additional Context
I've not inspected if this is in general problem with any nested objects.

@soyuka
Copy link
Member

soyuka commented Jan 13, 2025

PUT replaces everything I guess, isn't that working with PATCH though?

@ostrolucky
Copy link
Contributor Author

ostrolucky commented Jan 13, 2025

PUT with standard_put: true replaces everything. PUT with standard_put: false is designed to replace only fields that are specified in payload. But this doesn't seem working correctly for nested objects/embeddables.

PATCH requires json-patch payload, which is whole different league for our frontend to implement. This is why we do not use it.

@mrossard
Copy link
Contributor

That's an "old" awkward behavior of the non-standard PUT as far as I remember; it's a PATCH-like that completely replaces the contents of the included top-level properties of the resource.

@dunglas
Copy link
Member

dunglas commented Jan 15, 2025

For the record, our PATCH uses the JSON Merge Patch format, which is very similar to what you can do with the non-standard PUT (that we plan to deprecate at some point).

JSON Patch (which is indeed not very common, even if very practical) is currently not supported by API Platform (but that would be nice to have).

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

No branches or pull requests

4 participants