kuba-end / apilo

0 stars 0 forks source link

Attempting to use non-attribute class \"Symfony\\Component\\Validator\\Constraints\\Optional\" as attribute #1

Open akawalko opened 1 week ago

akawalko commented 1 week ago

I got an exception when calling the endpoint. My setup: PHP 8.1.2-1ubuntu2.18 (cli) (built: Jun 14 2024 15:52:55) (NTS) Ubuntu 22.04.4 LTS

curl --header "Content-Type: application/json" --request POST --data '{"city":"kozy"}' http://localhost:8000/api/inpost/points

{ "type": "https://tools.ietf.org/html/rfc2616#section-10", "title": "An error occurred", "status": 500, "detail": "Attempting to use non-attribute class \"Symfony\Component\Validator\Constraints\Optional\" as attribute", "class": "Error", "trace": [ { "namespace": "", "short_class": "", "class": "", "type": "", "function": "", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php", "line": 106, "args": [] }, { "namespace": "", "short_class": "ReflectionAttribute", "class": "ReflectionAttribute", "type": "->", "function": "newInstance", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php", "line": 106, "args": [] }, { "namespace": "Symfony\Component\Validator\Mapping\Loader", "short_class": "AnnotationLoader", "class": "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader", "type": "->", "function": "getAnnotations", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php", "line": 57, "args": [] }, { "namespace": "Symfony\Component\Validator\Mapping\Loader", "short_class": "AnnotationLoader", "class": "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader", "type": "->", "function": "loadClassMetadata", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Mapping/Loader/LoaderChain.php", "line": 51, "args": [] }, { "namespace": "Symfony\Component\Validator\Mapping\Loader", "short_class": "LoaderChain", "class": "Symfony\Component\Validator\Mapping\Loader\LoaderChain", "type": "->", "function": "loadClassMetadata", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Mapping/Factory/LazyLoadingMetadataFactory.php", "line": 99, "args": [] }, { "namespace": "Symfony\Component\Validator\Mapping\Factory", "short_class": "LazyLoadingMetadataFactory", "class": "Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory", "type": "->", "function": "getMetadataFor", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Validator/RecursiveContextualValidator.php", "line": 292, "args": [] }, { "namespace": "Symfony\Component\Validator\Validator", "short_class": "RecursiveContextualValidator", "class": "Symfony\Component\Validator\Validator\RecursiveContextualValidator", "type": "->", "function": "validateObject", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Validator/RecursiveContextualValidator.php", "line": 133, "args": [] }, { "namespace": "Symfony\Component\Validator\Validator", "short_class": "RecursiveContextualValidator", "class": "Symfony\Component\Validator\Validator\RecursiveContextualValidator", "type": "->", "function": "validate", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Validator/RecursiveValidator.php", "line": 82, "args": [] }, { "namespace": "Symfony\Component\Validator\Validator", "short_class": "RecursiveValidator", "class": "Symfony\Component\Validator\Validator\RecursiveValidator", "type": "->", "function": "validate", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php", "line": 127, "args": [] }, { "namespace": "Symfony\Component\HttpKernel\Controller\ArgumentResolver", "short_class": "RequestPayloadValueResolver", "class": "Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestPayloadValueResolver", "type": "->", "function": "onKernelControllerArguments", "file": "/home/example_user/kuba-end/vendor/symfony/event-dispatcher/EventDispatcher.php", "line": 260, "args": [] }, { "namespace": "Symfony\Component\EventDispatcher", "short_class": "EventDispatcher", "class": "Symfony\Component\EventDispatcher\EventDispatcher", "type": "::", "function": "Symfony\Component\EventDispatcher\{closure}", "file": "/home/example_user/kuba-end/vendor/symfony/event-dispatcher/EventDispatcher.php", "line": 220, "args": [] }, { "namespace": "Symfony\Component\EventDispatcher", "short_class": "EventDispatcher", "class": "Symfony\Component\EventDispatcher\EventDispatcher", "type": "->", "function": "callListeners", "file": "/home/example_user/kuba-end/vendor/symfony/event-dispatcher/EventDispatcher.php", "line": 56, "args": [] }, { "namespace": "Symfony\Component\EventDispatcher", "short_class": "EventDispatcher", "class": "Symfony\Component\EventDispatcher\EventDispatcher", "type": "->", "function": "dispatch", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/HttpKernel.php", "line": 176, "args": [] }, { "namespace": "Symfony\Component\HttpKernel", "short_class": "HttpKernel", "class": "Symfony\Component\HttpKernel\HttpKernel", "type": "->", "function": "handleRaw", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/HttpKernel.php", "line": 76, "args": [] }, { "namespace": "Symfony\Component\HttpKernel", "short_class": "HttpKernel", "class": "Symfony\Component\HttpKernel\HttpKernel", "type": "->", "function": "handle", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/Kernel.php", "line": 197, "args": [] }, { "namespace": "Symfony\Component\HttpKernel", "short_class": "Kernel", "class": "Symfony\Component\HttpKernel\Kernel", "type": "->", "function": "handle", "file": "/home/example_user/kuba-end/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php", "line": 35, "args": [] }, { "namespace": "Symfony\Component\Runtime\Runner\Symfony", "short_class": "HttpKernelRunner", "class": "Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner", "type": "->", "function": "run", "file": "/home/example_user/kuba-end/vendor/autoload_runtime.php", "line": 29, "args": [] }, { "namespace": "", "short_class": "", "class": "", "type": "", "function": "require_once", "file": "/home/example_user/kuba-end/public/index.php", "line": 5, "args": [ [ "string", "/home/example_user/kuba-end/vendor/autoload_runtime.php" ] ] } ] }

kuba-end commented 1 week ago

Ciekawa sprawa, w klasie na którą jest mapowany request storm świeci informacją [image: image.png] chyba wcześniej się nie spotkałem żebym skótem alt+enter zmienił vendorowe pliki co tutaj miało miejsce, zastąpiłem atrybut wspieraną adnotacją, po ponownym pullu będzie działało

śr., 26 cze 2024 o 13:20 Arkadiusz Kawałko @.***> napisał(a):

I got an exception when calling the endpoint. My setup: PHP 8.1.2-1ubuntu2.18 (cli) (built: Jun 14 2024 15:52:55) (NTS) Bare bone Ubuntu 22.04.4 LTS, not docker.

curl --header "Content-Type: application/json" --request POST --data '{"city":"kozy"}' http://localhost:8000/api/inpost/points

{ "type": "https://tools.ietf.org/html/rfc2616#section-10", "title": "An error occurred", "status": 500, "detail": "Attempting to use non-attribute class \"Symfony\Component\Validator\Constraints\Optional\" as attribute", "class": "Error", "trace": [ { "namespace": "", "short_class": "", "class": "", "type": "", "function": "", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php", "line": 106, "args": [] }, { "namespace": "", "short_class": "ReflectionAttribute", "class": "ReflectionAttribute", "type": "->", "function": "newInstance", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php", "line": 106, "args": [] }, { "namespace": "Symfony\Component\Validator\Mapping\Loader", "short_class": "AnnotationLoader", "class": "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader", "type": "->", "function": "getAnnotations", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php", "line": 57, "args": [] }, { "namespace": "Symfony\Component\Validator\Mapping\Loader", "short_class": "AnnotationLoader", "class": "Symfony\Component\Validator\Mapping\Loader\AnnotationLoader", "type": "->", "function": "loadClassMetadata", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Mapping/Loader/LoaderChain.php", "line": 51, "args": [] }, { "namespace": "Symfony\Component\Validator\Mapping\Loader", "short_class": "LoaderChain", "class": "Symfony\Component\Validator\Mapping\Loader\LoaderChain", "type": "->", "function": "loadClassMetadata", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Mapping/Factory/LazyLoadingMetadataFactory.php", "line": 99, "args": [] }, { "namespace": "Symfony\Component\Validator\Mapping\Factory", "short_class": "LazyLoadingMetadataFactory", "class": "Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory", "type": "->", "function": "getMetadataFor", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Validator/RecursiveContextualValidator.php", "line": 292, "args": [] }, { "namespace": "Symfony\Component\Validator\Validator", "short_class": "RecursiveContextualValidator", "class": "Symfony\Component\Validator\Validator\RecursiveContextualValidator", "type": "->", "function": "validateObject", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Validator/RecursiveContextualValidator.php", "line": 133, "args": [] }, { "namespace": "Symfony\Component\Validator\Validator", "short_class": "RecursiveContextualValidator", "class": "Symfony\Component\Validator\Validator\RecursiveContextualValidator", "type": "->", "function": "validate", "file": "/home/example_user/kuba-end/vendor/symfony/validator/Validator/RecursiveValidator.php", "line": 82, "args": [] }, { "namespace": "Symfony\Component\Validator\Validator", "short_class": "RecursiveValidator", "class": "Symfony\Component\Validator\Validator\RecursiveValidator", "type": "->", "function": "validate", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php", "line": 127, "args": [] }, { "namespace": "Symfony\Component\HttpKernel\Controller\ArgumentResolver", "short_class": "RequestPayloadValueResolver", "class": "Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestPayloadValueResolver", "type": "->", "function": "onKernelControllerArguments", "file": "/home/example_user/kuba-end/vendor/symfony/event-dispatcher/EventDispatcher.php", "line": 260, "args": [] }, { "namespace": "Symfony\Component\EventDispatcher", "short_class": "EventDispatcher", "class": "Symfony\Component\EventDispatcher\EventDispatcher", "type": "::", "function": "Symfony\Component\EventDispatcher\{closure}", "file": "/home/example_user/kuba-end/vendor/symfony/event-dispatcher/EventDispatcher.php", "line": 220, "args": [] }, { "namespace": "Symfony\Component\EventDispatcher", "short_class": "EventDispatcher", "class": "Symfony\Component\EventDispatcher\EventDispatcher", "type": "->", "function": "callListeners", "file": "/home/example_user/kuba-end/vendor/symfony/event-dispatcher/EventDispatcher.php", "line": 56, "args": [] }, { "namespace": "Symfony\Component\EventDispatcher", "short_class": "EventDispatcher", "class": "Symfony\Component\EventDispatcher\EventDispatcher", "type": "->", "function": "dispatch", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/HttpKernel.php", "line": 176, "args": [] }, { "namespace": "Symfony\Component\HttpKernel", "short_class": "HttpKernel", "class": "Symfony\Component\HttpKernel\HttpKernel", "type": "->", "function": "handleRaw", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/HttpKernel.php", "line": 76, "args": [] }, { "namespace": "Symfony\Component\HttpKernel", "short_class": "HttpKernel", "class": "Symfony\Component\HttpKernel\HttpKernel", "type": "->", "function": "handle", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/Kernel.php", "line": 197, "args": [] }, { "namespace": "Symfony\Component\HttpKernel", "short_class": "Kernel", "class": "Symfony\Component\HttpKernel\Kernel", "type": "->", "function": "handle", "file": "/home/example_user/kuba-end/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php", "line": 35, "args": [] }, { "namespace": "Symfony\Component\Runtime\Runner\Symfony", "short_class": "HttpKernelRunner", "class": "Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner", "type": "->", "function": "run", "file": "/home/example_user/kuba-end/vendor/autoload_runtime.php", "line": 29, "args": [] }, { "namespace": "", "short_class": "", "class": "", "type": "", "function": "require_once", "file": "/home/example_user/kuba-end/public/index.php", "line": 5, "args": [ [ "string", "/home/example_user/kuba-end/vendor/autoload_runtime.php" ] ] } ] }

— Reply to this email directly, view it on GitHub https://github.com/kuba-end/apilo/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANTYAA3UHCZIWBIU6CDEJ73ZJKPXDAVCNFSM6AAAAABJ5VR2D2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3TKMBWGU2TSMY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Rudziński Jakub

akawalko commented 1 week ago

Niestey dalej sypie błędem, ale innej natury. Sam Optionala nie używałem, więc też robię wielkie oczy ze zdziwienia że coś w Symfony niedziała :-) Optional wydaje się działać jedynie na kolekcji? link { "type": "https://tools.ietf.org/html/rfc2616#section-10", "title": "An error occurred", "status": 500, "detail": "[Semantical Error] Annotation @Assert\Optional is not allowed to be declared on property App\DTO\QueryPointDTO::$postalCode. You may only use this annotation on these code elements: ANNOTATION.", "class": "Doctrine\Common\Annotations\AnnotationException", "trace": [ { "namespace": "", "short_class": "", "class": "", "type": "", "function": "", "file": "/home/example_user/kuba-end/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php", "line": 36, "args": [] }, { "namespace": "Doctrine\Common\Annotations", "short_class": "AnnotationException", "class": "Doctrine\Common\Annotations\AnnotationException", "type": "::", "function": "semanticalError", "file": "/home/example_user/kuba-end/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php", "line": 857, "args": [] }, { "namespace": "Doctrine\Common\Annotations", "short_class": "DocParser", "class": "Doctrine\Common\Annotations\DocParser", "type": "->", "function": "Annotation", "file": "/home/example_user/kuba-end/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php", "line": 712, "args": [] }, { "namespace": "Doctrine\Common\Annotations", "short_class": "DocParser", "class": "Doctrine\Common\Annotations\DocParser", "type": "->", "function": "Annotations", "file": "/home/example_user/kuba-end/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php", "line": 368, "args": [] }, { "namespace": "Doctrine\Common\Annotations", "short_class": "DocParser", "class": "Doctrine\Common\Annotations\DocParser", "type": "->", "function": "parse", "file": "/home/example_user/kuba-end/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php", "line": 174, "args": [] }, { "namespace": "Doctrine\Common\Annotations", "short_class": "AnnotationReader", "class": "Doctrine\Common\Annotations\AnnotationReader", "type": "->", "function": "getPropertyAnnotations", "file": "/home/example_user/kuba-end/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PsrCachedReader.php", "line": 155, "args": [] }, { "namespace": "Doctrine\Common\Annotations", "short_class": "PsrCachedReader", "class": "Doctrine\Common\Annotations\PsrCachedReader", "type": "->", "function": "fetchFromCache", "file": "/home/example_user/kuba-end/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PsrCachedReader.php", "line": 88, "args": [] }, { "namespace": "Doctrine\Common\Annotations", "short_class": "PsrCachedReader", "class": "Doctrine\Common\Annotations\PsrCachedReader", "type": "->", "function": "getPropertyAnnotations", "file": "/home/example_user/kuba-end/vendor/symfony/serializer/Mapping/Loader/AnnotationLoader.php", "line": 202, "args": [] }, { "namespace": "Symfony\Component\Serializer\Mapping\Loader", "short_class": "AnnotationLoader", "class": "Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader", "type": "->", "function": "loadAnnotations", "file": "/home/example_user/kuba-end/vendor/symfony/serializer/Mapping/Loader/AnnotationLoader.php", "line": 75, "args": [] }, { "namespace": "Symfony\Component\Serializer\Mapping\Loader", "short_class": "AnnotationLoader", "class": "Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader", "type": "->", "function": "loadClassMetadata", "file": "/home/example_user/kuba-end/vendor/symfony/serializer/Mapping/Loader/LoaderChain.php", "line": 51, "args": [] }, { "namespace": "Symfony\Component\Serializer\Mapping\Loader", "short_class": "LoaderChain", "class": "Symfony\Component\Serializer\Mapping\Loader\LoaderChain", "type": "->", "function": "loadClassMetadata", "file": "/home/example_user/kuba-end/vendor/symfony/serializer/Mapping/Factory/ClassMetadataFactory.php", "line": 46, "args": [] }, { "namespace": "Symfony\Component\Serializer\Mapping\Factory", "short_class": "ClassMetadataFactory", "class": "Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory", "type": "->", "function": "getMetadataFor", "file": "/home/example_user/kuba-end/vendor/symfony/serializer/Normalizer/AbstractNormalizer.php", "line": 238, "args": [] }, { "namespace": "Symfony\Component\Serializer\Normalizer", "short_class": "AbstractNormalizer", "class": "Symfony\Component\Serializer\Normalizer\AbstractNormalizer", "type": "->", "function": "getAllowedAttributes", "file": "/home/example_user/kuba-end/vendor/symfony/serializer/Normalizer/ObjectNormalizer.php", "line": 151, "args": [] }, { "namespace": "Symfony\Component\Serializer\Normalizer", "short_class": "ObjectNormalizer", "class": "Symfony\Component\Serializer\Normalizer\ObjectNormalizer", "type": "->", "function": "getAllowedAttributes", "file": "/home/example_user/kuba-end/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php", "line": 320, "args": [] }, { "namespace": "Symfony\Component\Serializer\Normalizer", "short_class": "AbstractObjectNormalizer", "class": "Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer", "type": "->", "function": "denormalize", "file": "/home/example_user/kuba-end/vendor/symfony/serializer/Serializer.php", "line": 227, "args": [] }, { "namespace": "Symfony\Component\Serializer", "short_class": "Serializer", "class": "Symfony\Component\Serializer\Serializer", "type": "->", "function": "denormalize", "file": "/home/example_user/kuba-end/vendor/symfony/serializer/Serializer.php", "line": 152, "args": [] }, { "namespace": "Symfony\Component\Serializer", "short_class": "Serializer", "class": "Symfony\Component\Serializer\Serializer", "type": "->", "function": "deserialize", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php", "line": 194, "args": [] }, { "namespace": "Symfony\Component\HttpKernel\Controller\ArgumentResolver", "short_class": "RequestPayloadValueResolver", "class": "Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestPayloadValueResolver", "type": "->", "function": "mapRequestPayload", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php", "line": 107, "args": [] }, { "namespace": "Symfony\Component\HttpKernel\Controller\ArgumentResolver", "short_class": "RequestPayloadValueResolver", "class": "Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestPayloadValueResolver", "type": "->", "function": "onKernelControllerArguments", "file": "/home/example_user/kuba-end/vendor/symfony/event-dispatcher/EventDispatcher.php", "line": 260, "args": [] }, { "namespace": "Symfony\Component\EventDispatcher", "short_class": "EventDispatcher", "class": "Symfony\Component\EventDispatcher\EventDispatcher", "type": "::", "function": "Symfony\Component\EventDispatcher\{closure}", "file": "/home/example_user/kuba-end/vendor/symfony/event-dispatcher/EventDispatcher.php", "line": 220, "args": [] }, { "namespace": "Symfony\Component\EventDispatcher", "short_class": "EventDispatcher", "class": "Symfony\Component\EventDispatcher\EventDispatcher", "type": "->", "function": "callListeners", "file": "/home/example_user/kuba-end/vendor/symfony/event-dispatcher/EventDispatcher.php", "line": 56, "args": [] }, { "namespace": "Symfony\Component\EventDispatcher", "short_class": "EventDispatcher", "class": "Symfony\Component\EventDispatcher\EventDispatcher", "type": "->", "function": "dispatch", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/HttpKernel.php", "line": 176, "args": [] }, { "namespace": "Symfony\Component\HttpKernel", "short_class": "HttpKernel", "class": "Symfony\Component\HttpKernel\HttpKernel", "type": "->", "function": "handleRaw", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/HttpKernel.php", "line": 76, "args": [] }, { "namespace": "Symfony\Component\HttpKernel", "short_class": "HttpKernel", "class": "Symfony\Component\HttpKernel\HttpKernel", "type": "->", "function": "handle", "file": "/home/example_user/kuba-end/vendor/symfony/http-kernel/Kernel.php", "line": 197, "args": [] }, { "namespace": "Symfony\Component\HttpKernel", "short_class": "Kernel", "class": "Symfony\Component\HttpKernel\Kernel", "type": "->", "function": "handle", "file": "/home/example_user/kuba-end/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php", "line": 35, "args": [] }, { "namespace": "Symfony\Component\Runtime\Runner\Symfony", "short_class": "HttpKernelRunner", "class": "Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner", "type": "->", "function": "run", "file": "/home/example_user/kuba-end/vendor/autoload_runtime.php", "line": 29, "args": [] }, { "namespace": "", "short_class": "", "class": "", "type": "", "function": "require_once", "file": "/home/example_user/kuba-end/public/index.php", "line": 5, "args": [ [ "string", "/home/example_user/kuba-end/vendor/autoload_runtime.php" ] ] } ] }