core
core copied to clipboard
Issues found on 2.7
Write here as comment the errors you may found on api-platform/core:2.7.x-dev installed on your project. Please mention:
- the error message
- the related code if possible
- the service declaration, if specified
- the PHP version
- the Symfony version
- a fix proposal, if possible
- PHP 8.0.14
- Symfony 5.3.*
TypeError: App\Core\Api\IriConverter::__construct(): Argument #1 ($decorated) must be of type ApiPlatform\Core\Api\IriConverterInterface, ApiPlatform\Symfony\Routing\IriConverter given
# src/Core/Api/IriConverter.php
use ApiPlatform\Core\Api\IriConverterInterface;
final class IriConverter implements IriConverterInterface
{
public function __construct(private IriConverterInterface $decorated)
{
}
}
App\Core\Api\IriConverter:
decorates: api_platform.iri_converter
Bug: api_platform.symfony.iri_converter decorates api_platform.iri_converter.legacy which breaks the backward compatibility.
Fix: api_platform.symfony.iri_converter should not decorate api_platform.iri_converter.legacy but inject it as an argument.
- PHP 8.0.14
- Symfony 5.3.*
In deprecation.php line 483: Warning: Undefined array key "ApiPlatform\Core\Serializer\SerializerContextBuilderInterface"
Command executed: bin/console debug:event kernel.request -vvv
Fix: replace $deprecatedClasses by $deprecatedInterfaces in deprecation.php line 483
- PHP 8.0.14
- Symfony 5.3.*
Cannot retrieve collection operation attribute:
$operationName = $request->attributes->get('_api_collection_operation_name'); // api_broadcast_programmings_get_collection
$resourceMetadata->getCollectionOperationAttribute($operationName, 'filters_expression'); // null
Collection operations:
array:1 [
"get" => array:9 [
"repository_method" => "getCollection"
"filters_expression" => "request.query.get('segment') and (request.query.get('noEmiarte') or (request.query.get('intervalStartAt') and request.query.get('intervalEndAt')))"
"filters_message" => "Query parameter "segment" is required with "noEmiarte" or "intervalEndAt" and "scenario"."
"input" => null
"output" => null
"method" => "GET"
"stateless" => null
"input_formats" => array:4 [
"jsonld" => array:1 [
0 => "application/ld+json"
]
"json" => array:1 [
0 => "application/json"
]
"html" => array:1 [
0 => "text/html"
]
"csv" => array:1 [
0 => "text/csv"
]
]
"output_formats" => array:4 [
"jsonld" => array:1 [
0 => "application/ld+json"
]
"json" => array:1 [
0 => "application/json"
]
"html" => array:1 [
0 => "text/html"
]
"csv" => array:1 [
0 => "text/csv"
]
]
]
]
Bug: invalid collection operation name, got get instead of api_broadcast_programmings_get_collection (or the contrary)
- PHP 8.0.14
- Symfony 5.3.*
HTTP 400 invalid filters error message has changed from "detail": "..." to "hydra:description": "..."
- PHP 8.0.14
- Symfony 5.3.*
TypeError: Arte\Data\Bridge\ApiPlatform\DataProvider\Extension\PaginationExtension::__construct(): Argument #1 ($pagination) must be of type ApiPlatform\Core\DataProvider\Pagination, ApiPlatform\State\Pagination\Pagination given
# vendor/arte/data-bundle/src/Bridge/ApiPlatform/DataProvider/Extension/PaginationExtension.php
use ApiPlatform\Core\DataProvider\Pagination;
final class PaginationExtension implements CollectionExtensionInterface, ResultCollectionExtensionInterface
<service id="arte_data.api_platform.extension.pagination" class="Arte\Data\Bridge\ApiPlatform\DataProvider\Extension\PaginationExtension" public="false">
<argument type="service" id="api_platform.pagination"/>
<tag name="arte_data.api_platform.collection_extension" priority="-1"/>
</service>
- PHP 8.0.14
- Symfony 5.3.*
ApiPlatform\Exception\InvalidArgumentException: The filter class "Arte\Data\Bridge\ApiPlatform\DataProvider\Extension\Filter\SearchFilter" does not implement "ApiPlatform\Api\FilterInterface". Did you forget a use statement?
namespace Arte\Data\Bridge\ApiPlatform\DataProvider\Extension\Filter;
use ApiPlatform\Core\Api\FilterInterface as ApiFilterInterface;
interface FilterInterface extends ApiFilterInterface
PHP Fatal error: Cannot declare class ApiPlatform\State\Pagination\Pagination, because the name is already in use in /path/to/vendor/api-platform/core/src/Core/DataProvider/Pagination.php on line 29
You have requested a non-existent service "api_platform.doctrine.orm.metadata.property.metadata_factory"
Replace ApiPlatformExtension.php:873 by the following:
if ($this->isConfigEnabled($container, $config['doctrine'])) {
$remapDefinitionClasses['api_platform.doctrine.orm.metadata.property.metadata_factory'] = 'ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory';
}
You have requested a non-existent service "api_platform.metadata.property.metadata_factory.legacy".
Remove api_platform.metadata.property.metadata_factory.xml from $remapDefinitionClasses in ApiPlatformExtension.php, and add the following before the $remapDefinitionClasses declaration:
$container->getDefinition('api_platform.metadata.property.metadata_factory.xml')->setClass('ApiPlatform\Core\Metadata\Property\Factory\ExtractorPropertyMetadataFactory');
$container->setAlias('api_platform.metadata.property.metadata_factory.legacy', 'api_platform.metadata.property.metadata_factory.xml');
PHP Fatal error: During class fetch: Uncaught ReflectionException: Class "ApiPlatform\Core\Cache\CachedTrait" not found while loading "ApiPlatform\Core\Metadata\Property\Factory\CachedPropertyMetadataFactory".
Replace ApiPlatform\Core\Cache\CachedTrait by ApiPlatform\Util\CachedTrait in CachedPropertyMetadataFactory.php.
Attempted to load class "PropertyInfoPropertyMetadataFactory" from namespace "ApiPlatform\Metadata\Property". Did you forget a "use" statement for "ApiPlatform\Core\Bridge\Symfony\PropertyInfo\Metadata\Property\PropertyInfoPropertyMetadataFactory"?
Replace namespace ApiPlatform\Metadata\Property by ApiPlatform\Metadata\Property\Factory in PropertyInfoPropertyMetadataFactory.php.
ApiPlatform\Core\Metadata\Property\Factory\ExtractorPropertyMetadataFactory::__construct(): Argument #1 ($extractor) must be of type ApiPlatform\Core\Metadata\Extractor\ExtractorInterface, ApiPlatform\Core\Metadata\Extractor\XmlExtractor given
Create ExtractorInterface.php as following:
interface ExtractorInterface extends ResourceExtractorInterface
...and implement it in legacy XmlExtractor and YamlExtractor.
Replace api_platform.property.metadata_factory by api_platform.metadata.property.metadata_factory in ApiPlatformExtension.php
ApiPlatform\Core\Metadata\Property\Factory\AnnotationPropertyMetadataFactory::__construct(): Argument #2 ($decorated) must be of type ?ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface, ApiPlatform\Metadata\Property\Factory\PropertyInfoPropertyMetadataFactory given
Related service: api_platform.metadata.property.identifier_metadata_factory.annotation
Replace ApiPlatformExtension.php:852-856 with the following code:
$remapDefinitionDecorations = [
'api_platform.metadata.property.identifier_metadata_factory.xml',
'api_platform.metadata.property.identifier_metadata_factory.yaml',
'api_platform.metadata.property.identifier_metadata_factory.annotation',
];
foreach ($remapDefinitionDecorations as $definition) {
$container->getDefinition($definition)->setDecoratedService('api_platform.metadata.property.metadata_factory');
}
TypeError: ApiPlatform\Core\Metadata\Property\Factory\AnnotationPropertyMetadataFactory::withDeprecatedAttributes(): Argument #1 ($propertyMetadata) must be of type ApiPlatform\Metadata\ApiProperty, ApiPlatform\Core\Metadata\Property\PropertyMetadata given, called in /home/les-tilleuls/Sites/api-platform/core/src/Core/Metadata/Property/Factory/AnnotationPropertyMetadataFactory.php on line 160
php 8.0.12
Hello,
php bin/console debug:event kernel.request -vvv
In DefinitionErrorExceptionPass.php line 54:
[Symfony\Component\DependencyInjection\Exception\RuntimeException]
Cannot autowire service "annotated_app_entity_g_e_s_a_c_activo_api_platform_doctrine_orm_filter_search_filter": arg
ument "$iriConverter" of method "ApiPlatform\Doctrine\Orm\Filter\SearchFilter::__construct()" has no type-hint, you
should configure its value explicitly.
Exception trace:
at C:\appbackend\vendor\symfony\dependency-injection\Compiler\DefinitionErrorExceptionPass.php:54
Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue() at C:\appbackend\vendor\symfony\dependency-injection\Compiler\AbstractRecursivePass.php:82
Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at C:\appbackend\vendor\symfony\dependency-injection\Compiler\DefinitionErrorExceptionPass.php:32
Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue() at C:\appbackend\vendor\symfony\dependency-injection\Compiler\AbstractRecursivePass.php:47
Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process() at C:\appbackend\vendor\symfony\dependency-injection\Compiler\Compiler.php:91
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at C:\appbackend\vendor\symfony\dependency-injection\ContainerBuilder.php:744
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at C:\appbackend\vendor\symfony\http-kernel\Kernel.php:545
Symfony\Component\HttpKernel\Kernel->initializeContainer() at C:\appbackend\vendor\symfony\http-kernel\Kernel.php:786
Symfony\Component\HttpKernel\Kernel->preBoot() at C:\appbackend\vendor\symfony\http-kernel\Kernel.php:125
Symfony\Component\HttpKernel\Kernel->boot() at C:\appbackend\vendor\symfony\framework-bundle\Console\Application.php:168
Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at C:\appbackend\vendor\symfony\framework-bundle\Console\Application.php:74
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at C:\appbackend\vendor\symfony\console\Application.php:167
Symfony\Component\Console\Application->run() at C:\appbackend\bin\console:43
C:\appbackend\vendor\api-platform\core\src\Doctrine\Orm\Filter\SearchFilter.php
public function __construct(ManagerRegistry $managerRegistry, ?RequestStack $requestStack, $iriConverter, PropertyAccessorInterface $propertyAccessor = null, LoggerInterface $logger = null, array $properties = null, IdentifiersExtractorInterface $identifiersExtractor = null, NameConverterInterface $nameConverter = null)
{
IriConverterInterface $iriConverter
Hello,
This issue should probably pinned, anyways here is another "error":
In DecoratorServicePass.php line 80:
The service "api_platform.doctrine_mongodb.odm.metadata.property.identifier_metadata_factory" has a dependency on a non-existent service "api_platform.metadata.property.identifier_metadata_factory".
Thanks!
Hi!
On composer update with "api-platform/core": "v2.7.0-alpha.1" (same on 2.7.x-dev):
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
!!
!! In DefinitionErrorExceptionPass.php line 54:
!!
!! Cannot autowire service "annotated_user_interface_bank_rest_bank_account_pr
!! ojection_api_platform_elasticsearch_filter_order_filter": argument "$proper
!! tyMetadataFactory" of method "ApiPlatform\Elasticsearch\Filter\OrderFilter:
!! :__construct()" has no type-hint, you should configure its value explicitly
!! .
!!
!!
!!
Script @auto-scripts was called via post-update-cmd
Edit: fixed by https://github.com/api-platform/core/pull/4718. Thanks @soyuka
- The error message (on
composer update):The service "api_platform.doctrine.listener.http_cache.purge" has a dependency on a non-existent service "api_platform.http_cache.purger.xkey". Did you mean this: "api_platform.http_cache.purger.varnish"?
- PHP 8.1
- Symfony
6.0.*,6.1-alpha - api-platform/core
2.7.x-dev,2.7.0-alpha1
.env
VARNISH_URL='localhost:6082'
api-platform.yaml
http_cache:
invalidation:
enabled: true
varnish_urls: ['%env(VARNISH_URL)%']
public: true
defaults:
cache_headers:
max_age: 0
shared_max_age: 3600
vary: ['Content-Type', 'Authorization', 'Origin']
On 2.6.* it works without error message.
TypeError : ApiPlatform\Core\Bridge\Elasticsearch\DataProvider\CollectionDataProvider::__construct(): Argument #5 ($pagination) must be of type ApiPlatform\State\Pagination\Pagination, ApiPlatform\Core\DataProvider\Pagination given
The CollectionDataProvider is configured to use ApiPlatform\State\Pagination\Pagination which is the api_platform.pagination service.
However in the legacy/backward_compatibility.xml config the api_platform.pagination service is overwritten and marked an alias for api_platform.pagination.legacy, causing an error when fetching the CollectionDataProvider from the container.
@dgfmdrv should be fixed since https://github.com/api-platform/core/commit/e21a01aed0c1f8f83a3c6fe9f281c388c1a96276
@zakjakub I fixed this on main I think it'll be fixed in the next alpha version
Thanks to everyone, I'm working on improving the Elasticsearch support as per comment.
A small one. After https://github.com/api-platform/core/pull/4718 no errors after composer install. Running my test suite I get:
Error : Undefined constant ApiPlatform\Elasticsearch\Serializer\ItemNormalizer::FORMAT
If I put this in manually, my test suite passes. I'm on php 8.1, symfony 6.0.x, have 290 functional tests for endpoint testing, using doctrine, elasticsearch and custom search filters.
Oh my bad I didn't wanted to close this one let's leave it open for upcoming issues.
Hello, I'm testing the new version (2.7.0-alpha.2) on a fairly simple project (for now). The compatibility layer seems to work just fine as everything still work correctly so far after the upgrade.
Now I want to play with the new metadata system so I ran the command api:upgrade-resource and I have two remarks:
- the command changed the code style of all my API resources : I'm not sure it will be possible to do something to prevent that. It will take some time to fix the CS after the command, but that's ok.
- the command correctly upgraded almost all my metadata but completely ignored everything related to subresources:
- the
#[ApiSubresource]attribute stayed in place (but its import has been removed) - all the operations defined in
subresourceOperationsare gone. A line withuse ApiPlatform\Metadata\Link;has been added but is not used. Is that intended and I should upgrade these operations manually, or is there an issue with my code or the command?
- the
Anyway thanks for the good work, this new version looks very promising 👏
PHP 8.0 Symfony 5.4 API Platform 2.7.0-alpha.2 (metadata_backward_compatibility_layer: false)
Not an error but some deprecations. Both are logged a few hundred times.
User Deprecated: Since api-platform/core 2.7: Decorating the legacy ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface is deprecated, use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface instead.
User Deprecated: "ApiPlatform\Core\Metadata\Property\PropertyMetadata::ApiPlatform\Core\Metadata\Property\PropertyMetadata::isChildInherited" is deprecated since 2.4 and will be removed in 3.0.
This one is called but there are no subresources configured
User Deprecated: Since api-platform/core 2.7: Subresources are deprecated, use alternate URLs instead.
Thanks so much for the feedbacks.
@jonag
the command changed the code style of all my API resources : I'm not sure it will be possible to do something to prevent that. It will take some time to fix the CS after the command, but that's ok.
Don't you have some kind of php-cs-fixer to help you with that? I've tried my best but indeed php-parser does change the code style :/.
the command correctly upgraded almost all my metadata but completely ignored everything related to subresources: the #[ApiSubresource] attribute stayed in place (but its import has been removed) all the operations defined in subresourceOperations are gone. A line with use ApiPlatform\Metadata\Link; has been added but is not used. Is that intended and I should upgrade these operations manually, or is there an issue with my code or the command?
Are you sure ? It should've built new Operations on the concern Resource. Say you have a subresource that returns Address on Book, check your Address resource, there should be a new #[Get] operation using the old subresource metadata. In API Platform 3, a subresource is just another resource.
Links are there to specify links between resources, you can read more on the subject here: https://api-platform.com/docs/main/core/subresources/ (make sure you're on the 2.7 branch).
@dannyvw mhh on a fresh project these don't show up, are you sure you're not using any of the deprecated interfaces? Would it be possible for you to give me stack traces or a way to reproduce? Thanks!
I have one myself about childInherited I'll track this one and check if I can give you a way to remove it.
@soyuka I don't use the interface(s) in any custom code. API Platform is added in an existing project with a few new resources and the new metadata system with configuration in XML.
I will try this week to create a stack trace or a reproducer.
With v2.7.0-alpha.2 a few errors pop up in my tests. See stacktraces below. Let me know if you need more to continue.
Also: has the ApiPlatform\Core\Validator\ValidatorInterface been removed?
Error : Typed property Application\Engagement\Command\ChangePhaseCommand::$engagementId must not be accessed before initialization
/home/www/app/src/Application/Engagement/Validation/ChangePhaseEngagementMustHaveThreeRequiredPhasesConstraintValidator.php:50
/home/www/app/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:758
/home/www/app/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:603
/home/www/app/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:517
/home/www/app/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:314
/home/www/app/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:139
/home/www/app/vendor/symfony/validator/Validator/RecursiveValidator.php:97
/home/www/app/vendor/symfony/validator/Validator/TraceableValidator.php:67
/home/www/app/vendor/api-platform/core/src/Symfony/Validator/Validator.php:67
/home/www/app/vendor/api-platform/core/src/Symfony/EventListener/ValidateListener.php:97
/home/www/app/src/Infrastructure/Shared/ApiPlatform/Listener/ValidateListener.php:41
/home/www/app/vendor/symfony/event-dispatcher/Debug/WrappedListener.php:111
/home/www/app/vendor/symfony/event-dispatcher/EventDispatcher.php:230
/home/www/app/vendor/symfony/event-dispatcher/EventDispatcher.php:59
/home/www/app/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:152
/home/www/app/vendor/symfony/http-kernel/HttpKernel.php:157
/home/www/app/vendor/symfony/http-kernel/HttpKernel.php:74
/home/www/app/vendor/symfony/http-kernel/Kernel.php:202
/home/www/app/vendor/symfony/http-kernel/HttpKernelBrowser.php:65
/home/www/app/vendor/symfony/framework-bundle/KernelBrowser.php:172
/home/www/app/vendor/symfony/browser-kit/AbstractBrowser.php:370
/home/www/app/vendor/api-platform/core/src/Symfony/Bundle/Test/Client.php:124
/home/www/app/tests/Functional/UserInterface/Engagement/Rest/EngagementProjectionTest.php:1251
/home/www/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:726
/home/www/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
/home/www/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
/home/www/app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:673
Failed asserting that the Response status code is 404.
HTTP/1.1 202 Accepted
Accept-Patch: application/merge-patch+json
Cache-Control: no-cache, private
Content-Language: en
Content-Type: application/ld+json; charset=utf-8
Date: Tue, 26 Apr 2022 13:58:51 GMT
Link: <https://localhost/v1/docs?_format=jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"
Permissions-Policy: browsing-topics=()
Vary: Accept
Vary: Accept-Language
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-Robots-Tag: noindex
/home/www/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
/home/www/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
/home/www/app/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:142
/home/www/app/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:38
/home/www/app/tests/Functional/UserInterface/Engagement/Rest/EngagementProjectionTest.php:1394
/home/www/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:726
/home/www/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
/home/www/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
/home/www/app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:673
Failed asserting that the Response is successful.
HTTP/1.1 422 Unprocessable Content
Cache-Control: no-cache, private
Content-Language: en
Content-Type: application/ld+json; charset=utf-8
Date: Tue, 26 Apr 2022 14:01:06 GMT
Link: <https://localhost/v1/docs?_format=jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"
Permissions-Policy: browsing-topics=()
Vary: Accept-Language
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-Robots-Tag: noindex
{"@context":"\/v1\/contexts\/ConstraintViolationList","@type":"ConstraintViolationList","hydra:title":"An error occurred","hydra:description":"memberId: This value should be of type Domain\\Organisation\\MemberId.","violations":[{"propertyPath":"memberId","message":"This value should be of type Domain\\Organisation\\MemberId.","code":null}]}
/home/www/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
/home/www/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
/home/www/app/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:142
/home/www/app/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:33
/home/www/app/tests/Functional/UserInterface/Organisation/Rest/OrganisationProjectionTest.php:848
/home/www/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:726
/home/www/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
/home/www/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
/home/www/app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:673