Comments (4)
This is definitely a problem for us. My API uses entities from a shared library, and several entities have __clone functions that intentionally do not copy over the id. Things would be ok if the IRI wasn't generated based on previous data, but on current data.
from core.
OK. I have a work around for those of us who stubbornly wanted to update. You can decorate the WriteListener Here is my quick implementation. (I've just banged it out and not put it through any significant tests yet)
<?php
namespace App\EventListener;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Throwable;
#[AsDecorator('api_platform.listener.view.write')]
class WriteListener
{
public function __construct(private \ApiPlatform\Symfony\EventListener\WriteListener $decorated)
{
}
public function onKernelView(ViewEvent $event): void
{
$this->decorated->onKernelView($event);
$data = $event->getControllerResult();
$request = $event->getRequest();
$method = $request->getMethod();
if ('GET' === $method) {
try {
$originalData = $request->attributes->get('original_data');
if ($data->getId() && !$originalData->getId()) {
$request->attributes->set('original_data', $data);
}
} catch (Throwable) {
}
}
}
}
from core.
I'm not sure why is cloning original data even needed.
Thanks for the detailed report I'll fix this, indeed it looks like cloning is not needed there, can you confirm the patch solves your issue? Thanks.
from core.
@soyuka Works, thank you.
from core.
Related Issues (20)
- Upgrade to Symfony 7.1 seems to be breaking container linting
- Broken with symfony 7.1 HOT 2
- Unable to generate an IRI for the item of type App\ApiResource\*** with an UriTemplate HOT 1
- Support for JsonProblem (RFC 7807) Extension Member HOT 2
- Remove hydra prefix
- Filters incompatible with PHP 8.2.20 and 8.3.8 HOT 22
- Implement getType for ODM DoctrineExtractor HOT 1
- Mixing REST and GraphQL operation names HOT 3
- Access checks for a DTO created through a resolver should happen after it was created HOT 2
- Doctrine ODM Documents return inconsistent data for GET Collection and Item Operations in Symfony production environment HOT 1
- Calling GraphQL DeleteMutation ignores serialization groups and causes error HOT 2
- securityPostValidation argument on ApiResource and operations attributes is ignored when having use_symfony_listeners: true HOT 2
- Upgrade from 3.3.6 to 3.3.7 leads to 405 for OPTIONS request on / HOT 4
- Varnish invalidation on subresource HOT 1
- `DateFilter` does not work sometimes until the cache is cleared.
- JsonSchema validation fail for non-readable link with `assertMatchesResourceItemJsonSchema`
- v3.3.8: Embedded subresources no longer denormalizing HOT 19
- Error during PUT operation when using DTO and stateOptions HOT 1
- Metadata/ApiProperty.php default property has incorrect PHP annotation type HOT 1
- Invalid IRIs in output DTOs HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.