core icon indicating copy to clipboard operation
core copied to clipboard

Identifier DateTime url generator not working

Open louismariegaborit opened this issue 3 years ago • 0 comments

API Platform version(s) affected: 2.6.8

Description
I created a new resource which identifier is a datetime property. When I try using the property as an identifier, I have the following error. But, if I read the documentation, DateTime identifier seems to be supported.

Stacktrace (from json response)
  {
    "@context": "/contexts/Error",
    "@type": "hydra:Error",
    "hydra:title": "An error occurred",
    "hydra:description": "preg_match(): Argument #2 ($subject) must be of type string, DateTime given",
    "trace": [
      {
        "namespace": "",
        "short_class": "",
        "class": "",
        "type": "",
        "function": "",
        "file": "/srv/api/vendor/symfony/routing/Generator/UrlGenerator.php",
        "line": 190,
        "args": []
      },
      {
        "namespace": "",
        "short_class": "",
        "class": "",
        "type": "",
        "function": "preg_match",
        "file": "/srv/api/vendor/symfony/routing/Generator/UrlGenerator.php",
        "line": 190,
        "args": [
          [
            "string",
            "#^[^/\\.]++$#iu"
          ],
          [
            "object",
            "DateTime"
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\Routing\\Generator",
        "short_class": "UrlGenerator",
        "class": "Symfony\\Component\\Routing\\Generator\\UrlGenerator",
        "type": "->",
        "function": "doGenerate",
        "file": "/srv/api/vendor/symfony/routing/Generator/CompiledUrlGenerator.php",
        "line": 67,
        "args": [
          [
            "array",
            {
              "date": [
                "integer",
                0
              ],
              "_format": [
                "integer",
                1
              ]
            }
          ],
          [
            "array",
            {
              "_controller": [
                "string",
                "api_platform.action.get_item"
              ],
              "_format": [
                "null",
                null
              ],
              "_stateless": [
                "boolean",
                true
              ],
              "_api_resource_class": [
                "string",
                "App\\Entity\\CalendarEvent"
              ],
              "_api_identifiers": [
                "array",
                [
                  [
                    "string",
                    "date"
                  ]
                ]
              ],
              "_api_has_composite_identifier": [
                "boolean",
                false
              ],
              "_api_item_operation_name": [
                "string",
                "get"
              ]
            }
          ],
          [
            "array",
            []
          ],
          [
            "array",
            [
              [
                "array",
                [
                  [
                    "string",
                    "variable"
                  ],
                  [
                    "string",
                    "."
                  ],
                  [
                    "string",
                    "[^/]++"
                  ],
                  [
                    "string",
                    "_format"
                  ],
                  [
                    "boolean",
                    true
                  ]
                ]
              ],
              [
                "array",
                [
                  [
                    "string",
                    "variable"
                  ],
                  [
                    "string",
                    "/"
                  ],
                  [
                    "string",
                    "[^/\\.]++"
                  ],
                  [
                    "string",
                    "date"
                  ],
                  [
                    "boolean",
                    true
                  ]
                ]
              ],
              [
                "array",
                [
                  [
                    "string",
                    "text"
                  ],
                  [
                    "string",
                    "/calendar_events"
                  ]
                ]
              ]
            ]
          ],
          [
            "array",
            {
              "date": [
                "object",
                "DateTime"
              ]
            }
          ],
          [
            "string",
            "api_calendar_events_get_item"
          ],
          [
            "integer",
            1
          ],
          [
            "array",
            []
          ],
          [
            "array",
            []
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\Routing\\Generator",
        "short_class": "CompiledUrlGenerator",
        "class": "Symfony\\Component\\Routing\\Generator\\CompiledUrlGenerator",
        "type": "->",
        "function": "generate",
        "file": "/srv/api/vendor/symfony/routing/Router.php",
        "line": 225,
        "args": [
          [
            "string",
            "api_calendar_events_get_item"
          ],
          [
            "array",
            {
              "date": [
                "object",
                "DateTime"
              ]
            }
          ],
          [
            "integer",
            1
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\Routing",
        "short_class": "Router",
        "class": "Symfony\\Component\\Routing\\Router",
        "type": "->",
        "function": "generate",
        "file": "/srv/api/vendor/api-platform/core/src/Bridge/Symfony/Routing/Router.php",
        "line": 107,
        "args": [
          [
            "string",
            "api_calendar_events_get_item"
          ],
          [
            "array",
            {
              "date": [
                "object",
                "DateTime"
              ]
            }
          ],
          [
            "integer",
            1
          ]
        ]
      },
      {
        "namespace": "ApiPlatform\\Core\\Bridge\\Symfony\\Routing",
        "short_class": "Router",
        "class": "ApiPlatform\\Core\\Bridge\\Symfony\\Routing\\Router",
        "type": "->",
        "function": "generate",
        "file": "/srv/api/vendor/api-platform/core/src/Bridge/Symfony/Routing/IriConverter.php",
        "line": 156,
        "args": [
          [
            "string",
            "api_calendar_events_get_item"
          ],
          [
            "array",
            {
              "date": [
                "object",
                "DateTime"
              ]
            }
          ],
          [
            "integer",
            1
          ]
        ]
      },
      {
        "namespace": "ApiPlatform\\Core\\Bridge\\Symfony\\Routing",
        "short_class": "IriConverter",
        "class": "ApiPlatform\\Core\\Bridge\\Symfony\\Routing\\IriConverter",
        "type": "->",
        "function": "getItemIriFromResourceClass",
        "file": "/srv/api/vendor/api-platform/core/src/Bridge/Symfony/Routing/IriConverter.php",
        "line": 128,
        "args": [
          [
            "string",
            "App\\Entity\\CalendarEvent"
          ],
          [
            "array",
            {
              "date": [
                "object",
                "DateTime"
              ]
            }
          ],
          [
            "integer",
            1
          ]
        ]
      },
      {
        "namespace": "ApiPlatform\\Core\\Bridge\\Symfony\\Routing",
        "short_class": "IriConverter",
        "class": "ApiPlatform\\Core\\Bridge\\Symfony\\Routing\\IriConverter",
        "type": "->",
        "function": "getIriFromItem",
        "file": "/srv/api/vendor/api-platform/core/src/JsonLd/Serializer/ItemNormalizer.php",
        "line": 77,
        "args": [
          [
            "object",
            "App\\Entity\\CalendarEvent"
          ]
        ]
      },
      {
        "namespace": "ApiPlatform\\Core\\JsonLd\\Serializer",
        "short_class": "ItemNormalizer",
        "class": "ApiPlatform\\Core\\JsonLd\\Serializer\\ItemNormalizer",
        "type": "->",
        "function": "normalize",
        "file": "/srv/api/vendor/symfony/serializer/Serializer.php",
        "line": 161,
        "args": [
          [
            "object",
            "App\\Entity\\CalendarEvent"
          ],
          [
            "string",
            "jsonld"
          ],
          [
            "array",
            {
              "operation_type": [
                "string",
                "collection"
              ],
              "collection_operation_name": [
                "string",
                "get"
              ],
              "resource_class": [
                "string",
                "App\\Entity\\CalendarEvent"
              ],
              "iri_only": [
                "boolean",
                false
              ],
              "input": [
                "null",
                null
              ],
              "output": [
                "null",
                null
              ],
              "request_uri": [
                "string",
                "/calendar_events?page=1"
              ],
              "uri": [
                "string",
                "https://localhost/calendar_events?page=1"
              ],
              "skip_null_values": [
                "boolean",
                true
              ],
              "resources": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ],
              "exclude_from_cache_key": [
                "array",
                [
                  [
                    "string",
                    "resources"
                  ],
                  [
                    "string",
                    "resources_to_push"
                  ]
                ]
              ],
              "resources_to_push": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ],
              "api_sub_level": [
                "boolean",
                true
              ],
              "jsonld_has_context": [
                "boolean",
                true
              ]
            }
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\Serializer",
        "short_class": "Serializer",
        "class": "Symfony\\Component\\Serializer\\Serializer",
        "type": "->",
        "function": "normalize",
        "file": "/srv/api/vendor/api-platform/core/src/Hydra/Serializer/CollectionNormalizer.php",
        "line": 94,
        "args": [
          [
            "object",
            "App\\Entity\\CalendarEvent"
          ],
          [
            "string",
            "jsonld"
          ],
          [
            "array",
            {
              "operation_type": [
                "string",
                "collection"
              ],
              "collection_operation_name": [
                "string",
                "get"
              ],
              "resource_class": [
                "string",
                "App\\Entity\\CalendarEvent"
              ],
              "iri_only": [
                "boolean",
                false
              ],
              "input": [
                "null",
                null
              ],
              "output": [
                "null",
                null
              ],
              "request_uri": [
                "string",
                "/calendar_events?page=1"
              ],
              "uri": [
                "string",
                "https://localhost/calendar_events?page=1"
              ],
              "skip_null_values": [
                "boolean",
                true
              ],
              "resources": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ],
              "exclude_from_cache_key": [
                "array",
                [
                  [
                    "string",
                    "resources"
                  ],
                  [
                    "string",
                    "resources_to_push"
                  ]
                ]
              ],
              "resources_to_push": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ],
              "api_sub_level": [
                "boolean",
                true
              ],
              "jsonld_has_context": [
                "boolean",
                true
              ]
            }
          ]
        ]
      },
      {
        "namespace": "ApiPlatform\\Core\\Hydra\\Serializer",
        "short_class": "CollectionNormalizer",
        "class": "ApiPlatform\\Core\\Hydra\\Serializer\\CollectionNormalizer",
        "type": "->",
        "function": "normalize",
        "file": "/srv/api/vendor/api-platform/core/src/Hydra/Serializer/PartialCollectionViewNormalizer.php",
        "line": 57,
        "args": [
          [
            "object",
            "ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Paginator"
          ],
          [
            "string",
            "jsonld"
          ],
          [
            "array",
            {
              "operation_type": [
                "string",
                "collection"
              ],
              "collection_operation_name": [
                "string",
                "get"
              ],
              "resource_class": [
                "string",
                "App\\Entity\\CalendarEvent"
              ],
              "iri_only": [
                "boolean",
                false
              ],
              "input": [
                "null",
                null
              ],
              "output": [
                "null",
                null
              ],
              "request_uri": [
                "string",
                "/calendar_events?page=1"
              ],
              "uri": [
                "string",
                "https://localhost/calendar_events?page=1"
              ],
              "skip_null_values": [
                "boolean",
                true
              ],
              "resources": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ],
              "exclude_from_cache_key": [
                "array",
                [
                  [
                    "string",
                    "resources"
                  ],
                  [
                    "string",
                    "resources_to_push"
                  ]
                ]
              ],
              "resources_to_push": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ],
              "api_sub_level": [
                "boolean",
                true
              ],
              "jsonld_has_context": [
                "boolean",
                true
              ]
            }
          ]
        ]
      },
      {
        "namespace": "ApiPlatform\\Core\\Hydra\\Serializer",
        "short_class": "PartialCollectionViewNormalizer",
        "class": "ApiPlatform\\Core\\Hydra\\Serializer\\PartialCollectionViewNormalizer",
        "type": "->",
        "function": "normalize",
        "file": "/srv/api/vendor/api-platform/core/src/Hydra/Serializer/CollectionFiltersNormalizer.php",
        "line": 75,
        "args": [
          [
            "object",
            "ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Paginator"
          ],
          [
            "string",
            "jsonld"
          ],
          [
            "array",
            {
              "operation_type": [
                "string",
                "collection"
              ],
              "collection_operation_name": [
                "string",
                "get"
              ],
              "resource_class": [
                "string",
                "App\\Entity\\CalendarEvent"
              ],
              "iri_only": [
                "boolean",
                false
              ],
              "input": [
                "null",
                null
              ],
              "output": [
                "null",
                null
              ],
              "request_uri": [
                "string",
                "/calendar_events?page=1"
              ],
              "uri": [
                "string",
                "https://localhost/calendar_events?page=1"
              ],
              "skip_null_values": [
                "boolean",
                true
              ],
              "resources": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ],
              "exclude_from_cache_key": [
                "array",
                [
                  [
                    "string",
                    "resources"
                  ],
                  [
                    "string",
                    "resources_to_push"
                  ]
                ]
              ],
              "resources_to_push": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ]
            }
          ]
        ]
      },
      {
        "namespace": "ApiPlatform\\Core\\Hydra\\Serializer",
        "short_class": "CollectionFiltersNormalizer",
        "class": "ApiPlatform\\Core\\Hydra\\Serializer\\CollectionFiltersNormalizer",
        "type": "->",
        "function": "normalize",
        "file": "/srv/api/vendor/symfony/serializer/Serializer.php",
        "line": 161,
        "args": [
          [
            "object",
            "ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Paginator"
          ],
          [
            "string",
            "jsonld"
          ],
          [
            "array",
            {
              "operation_type": [
                "string",
                "collection"
              ],
              "collection_operation_name": [
                "string",
                "get"
              ],
              "resource_class": [
                "string",
                "App\\Entity\\CalendarEvent"
              ],
              "iri_only": [
                "boolean",
                false
              ],
              "input": [
                "null",
                null
              ],
              "output": [
                "null",
                null
              ],
              "request_uri": [
                "string",
                "/calendar_events?page=1"
              ],
              "uri": [
                "string",
                "https://localhost/calendar_events?page=1"
              ],
              "skip_null_values": [
                "boolean",
                true
              ],
              "resources": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ],
              "exclude_from_cache_key": [
                "array",
                [
                  [
                    "string",
                    "resources"
                  ],
                  [
                    "string",
                    "resources_to_push"
                  ]
                ]
              ],
              "resources_to_push": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ]
            }
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\Serializer",
        "short_class": "Serializer",
        "class": "Symfony\\Component\\Serializer\\Serializer",
        "type": "->",
        "function": "normalize",
        "file": "/srv/api/vendor/symfony/serializer/Serializer.php",
        "line": 134,
        "args": [
          [
            "object",
            "ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Paginator"
          ],
          [
            "string",
            "jsonld"
          ],
          [
            "array",
            {
              "operation_type": [
                "string",
                "collection"
              ],
              "collection_operation_name": [
                "string",
                "get"
              ],
              "resource_class": [
                "string",
                "App\\Entity\\CalendarEvent"
              ],
              "iri_only": [
                "boolean",
                false
              ],
              "input": [
                "null",
                null
              ],
              "output": [
                "null",
                null
              ],
              "request_uri": [
                "string",
                "/calendar_events?page=1"
              ],
              "uri": [
                "string",
                "https://localhost/calendar_events?page=1"
              ],
              "skip_null_values": [
                "boolean",
                true
              ],
              "resources": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ],
              "exclude_from_cache_key": [
                "array",
                [
                  [
                    "string",
                    "resources"
                  ],
                  [
                    "string",
                    "resources_to_push"
                  ]
                ]
              ],
              "resources_to_push": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ]
            }
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\Serializer",
        "short_class": "Serializer",
        "class": "Symfony\\Component\\Serializer\\Serializer",
        "type": "->",
        "function": "serialize",
        "file": "/srv/api/vendor/api-platform/core/src/EventListener/SerializeListener.php",
        "line": 95,
        "args": [
          [
            "object",
            "ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Paginator"
          ],
          [
            "string",
            "jsonld"
          ],
          [
            "array",
            {
              "operation_type": [
                "string",
                "collection"
              ],
              "collection_operation_name": [
                "string",
                "get"
              ],
              "resource_class": [
                "string",
                "App\\Entity\\CalendarEvent"
              ],
              "iri_only": [
                "boolean",
                false
              ],
              "input": [
                "null",
                null
              ],
              "output": [
                "null",
                null
              ],
              "request_uri": [
                "string",
                "/calendar_events?page=1"
              ],
              "uri": [
                "string",
                "https://localhost/calendar_events?page=1"
              ],
              "skip_null_values": [
                "boolean",
                true
              ],
              "resources": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ],
              "exclude_from_cache_key": [
                "array",
                [
                  [
                    "string",
                    "resources"
                  ],
                  [
                    "string",
                    "resources_to_push"
                  ]
                ]
              ],
              "resources_to_push": [
                "object",
                "ApiPlatform\\Core\\Serializer\\ResourceList"
              ]
            }
          ]
        ]
      },
      {
        "namespace": "ApiPlatform\\Core\\EventListener",
        "short_class": "SerializeListener",
        "class": "ApiPlatform\\Core\\EventListener\\SerializeListener",
        "type": "->",
        "function": "onKernelView",
        "file": "/srv/api/vendor/symfony/event-dispatcher/Debug/WrappedListener.php",
        "line": 111,
        "args": [
          [
            "object",
            "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
          ],
          [
            "string",
            "kernel.view"
          ],
          [
            "object",
            "Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher"
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\EventDispatcher\\Debug",
        "short_class": "WrappedListener",
        "class": "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener",
        "type": "->",
        "function": "__invoke",
        "file": "/srv/api/vendor/symfony/event-dispatcher/EventDispatcher.php",
        "line": 230,
        "args": [
          [
            "object",
            "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
          ],
          [
            "string",
            "kernel.view"
          ],
          [
            "object",
            "Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher"
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\EventDispatcher",
        "short_class": "EventDispatcher",
        "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
        "type": "->",
        "function": "callListeners",
        "file": "/srv/api/vendor/symfony/event-dispatcher/EventDispatcher.php",
        "line": 59,
        "args": [
          [
            "array",
            [
              [
                "object",
                "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
              ],
              [
                "object",
                "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
              ],
              [
                "object",
                "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
              ],
              [
                "object",
                "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
              ]
            ]
          ],
          [
            "string",
            "kernel.view"
          ],
          [
            "object",
            "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\EventDispatcher",
        "short_class": "EventDispatcher",
        "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
        "type": "->",
        "function": "dispatch",
        "file": "/srv/api/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php",
        "line": 152,
        "args": [
          [
            "object",
            "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
          ],
          [
            "string",
            "kernel.view"
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\EventDispatcher\\Debug",
        "short_class": "TraceableEventDispatcher",
        "class": "Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher",
        "type": "->",
        "function": "dispatch",
        "file": "/srv/api/vendor/symfony/http-kernel/HttpKernel.php",
        "line": 157,
        "args": [
          [
            "object",
            "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
          ],
          [
            "string",
            "kernel.view"
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\HttpKernel",
        "short_class": "HttpKernel",
        "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
        "type": "->",
        "function": "handleRaw",
        "file": "/srv/api/vendor/symfony/http-kernel/HttpKernel.php",
        "line": 74,
        "args": [
          [
            "object",
            "Symfony\\Component\\HttpFoundation\\Request"
          ],
          [
            "integer",
            1
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\HttpKernel",
        "short_class": "HttpKernel",
        "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
        "type": "->",
        "function": "handle",
        "file": "/srv/api/vendor/symfony/http-kernel/Kernel.php",
        "line": 202,
        "args": [
          [
            "object",
            "Symfony\\Component\\HttpFoundation\\Request"
          ],
          [
            "integer",
            1
          ],
          [
            "boolean",
            true
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\HttpKernel",
        "short_class": "Kernel",
        "class": "Symfony\\Component\\HttpKernel\\Kernel",
        "type": "->",
        "function": "handle",
        "file": "/srv/api/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php",
        "line": 35,
        "args": [
          [
            "object",
            "Symfony\\Component\\HttpFoundation\\Request"
          ]
        ]
      },
      {
        "namespace": "Symfony\\Component\\Runtime\\Runner\\Symfony",
        "short_class": "HttpKernelRunner",
        "class": "Symfony\\Component\\Runtime\\Runner\\Symfony\\HttpKernelRunner",
        "type": "->",
        "function": "run",
        "file": "/srv/api/vendor/autoload_runtime.php",
        "line": 29,
        "args": []
      },
      {
        "namespace": "",
        "short_class": "",
        "class": "",
        "type": "",
        "function": "require_once",
        "file": "/srv/api/public/index.php",
        "line": 5,
        "args": [
          [
            "string",
            "/srv/api/vendor/autoload_runtime.php"
          ]
        ]
      }
    ]
  }

How to reproduce
I created a test repository with my resource. Check the newest commit.

Could you confirm that is a bug ? In this case, I will work on a fix.

Thanks,

louismariegaborit avatar Aug 08 '22 14:08 louismariegaborit