Fix JSON:API Extras no longer returns array with Symfony 6.0

Created on 7 June 2023, over 1 year ago
Updated 10 June 2023, over 1 year ago

Problem/Motivation

🐛 $request->get may no longer return array as of Symfony 6.0 Fixed

When navigating to /api/node/landing_page_lb for example
Then the following JSON:API Internal Server Error
Expected a scalar value as a 2nd argument to \u0022Symfony\\Component\\HttpFoundation\\InputBag::get()\u0022, \u0022array\u0022 given.

{
   "jsonapi":{
      "version":"1.0",
      "meta":{
         "links":{
            "self":{
               "href":"http:\/\/jsonapi.org\/format\/1.0\/"
            }
         }
      }
   },
   "errors":[
      {
         "title":"Internal Server Error",
         "status":"500",
         "detail":"Expected a scalar value as a 2nd argument to \u0022Symfony\\Component\\HttpFoundation\\InputBag::get()\u0022, \u0022array\u0022 given.",
         "links":{
            "via":{
               "href":"http:\/\/r-natshah.dev.in.vardot.com\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb"
            },
            "info":{
               "href":"http:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616-sec10.html#sec10.5.1"
            }
         },
         "source":{
            "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/modules\/jsonapi\/src\/EventSubscriber\/DefaultExceptionSubscriber.php",
            "line":49
         },
         "meta":{
            "exception":"InvalidArgumentException: Expected a scalar value as a 2nd argument to \u0022Symfony\\Component\\HttpFoundation\\InputBag::get()\u0022, \u0022array\u0022 given. in \/var\/www\/html\/dev\/varbase10c1\/vendor\/symfony\/http-foundation\/InputBag.php:31\nStack trace:\n#0 \/var\/www\/html\/dev\/varbase10c1\/docroot\/modules\/contrib\/jsonapi_extras\/modules\/jsonapi_defaults\/src\/Controller\/EntityResource.php(77): Symfony\\Component\\HttpFoundation\\InputBag-\u003Eget()\n#1 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/modules\/jsonapi\/src\/Controller\/EntityResource.php(412): Drupal\\jsonapi_defaults\\Controller\\EntityResource-\u003EgetJsonApiParams()\n#2 [internal function]: Drupal\\jsonapi\\Controller\\EntityResource-\u003EgetCollection()\n#3 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/EventSubscriber\/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()\n#4 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/Render\/Renderer.php(583): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber-\u003EDrupal\\Core\\EventSubscriber\\{closure}()\n#5 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/EventSubscriber\/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\\Core\\Render\\Renderer-\u003EexecuteInRenderContext()\n#6 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/EventSubscriber\/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber-\u003EwrapControllerExecutionInRenderContext()\n#7 \/var\/www\/html\/dev\/varbase10c1\/vendor\/symfony\/http-kernel\/HttpKernel.php(166): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber-\u003EDrupal\\Core\\EventSubscriber\\{closure}()\n#8 \/var\/www\/html\/dev\/varbase10c1\/vendor\/symfony\/http-kernel\/HttpKernel.php(74): Symfony\\Component\\HttpKernel\\HttpKernel-\u003EhandleRaw()\n#9 \/var\/www\/html\/dev\/varbase10c1\/docroot\/modules\/contrib\/simple_oauth\/src\/HttpMiddleware\/BasicAuthSwap.php(54): Symfony\\Component\\HttpKernel\\HttpKernel-\u003Ehandle()\n#10 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/Session.php(58): Drupal\\simple_oauth\\HttpMiddleware\\BasicAuthSwap-\u003Ehandle()\n#11 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/KernelPreHandle.php(48): Drupal\\Core\\StackMiddleware\\Session-\u003Ehandle()\n#12 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/modules\/page_cache\/src\/StackMiddleware\/PageCache.php(106): Drupal\\Core\\StackMiddleware\\KernelPreHandle-\u003Ehandle()\n#13 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/modules\/page_cache\/src\/StackMiddleware\/PageCache.php(85): Drupal\\page_cache\\StackMiddleware\\PageCache-\u003Epass()\n#14 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/ReverseProxyMiddleware.php(48): Drupal\\page_cache\\StackMiddleware\\PageCache-\u003Ehandle()\n#15 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/NegotiationMiddleware.php(51): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware-\u003Ehandle()\n#16 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/StackedHttpKernel.php(51): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware-\u003Ehandle()\n#17 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/DrupalKernel.php(704): Drupal\\Core\\StackMiddleware\\StackedHttpKernel-\u003Ehandle()\n#18 \/var\/www\/html\/dev\/varbase10c1\/docroot\/index.php(19): Drupal\\Core\\DrupalKernel-\u003Ehandle()\n#19 {main}\n\nNext Symfony\\Component\\HttpKernel\\Exception\\HttpException: Expected a scalar value as a 2nd argument to \u0022Symfony\\Component\\HttpFoundation\\InputBag::get()\u0022, \u0022array\u0022 given. in \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/modules\/jsonapi\/src\/EventSubscriber\/DefaultExceptionSubscriber.php:49\nStack trace:\n#0 [internal function]: Drupal\\jsonapi\\EventSubscriber\\DefaultExceptionSubscriber-\u003EonException()\n#1 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Component\/EventDispatcher\/ContainerAwareEventDispatcher.php(111): call_user_func()\n#2 \/var\/www\/html\/dev\/varbase10c1\/vendor\/symfony\/http-kernel\/HttpKernel.php(224): Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher-\u003Edispatch()\n#3 \/var\/www\/html\/dev\/varbase10c1\/vendor\/symfony\/http-kernel\/HttpKernel.php(89): Symfony\\Component\\HttpKernel\\HttpKernel-\u003EhandleThrowable()\n#4 \/var\/www\/html\/dev\/varbase10c1\/docroot\/modules\/contrib\/simple_oauth\/src\/HttpMiddleware\/BasicAuthSwap.php(54): Symfony\\Component\\HttpKernel\\HttpKernel-\u003Ehandle()\n#5 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/Session.php(58): Drupal\\simple_oauth\\HttpMiddleware\\BasicAuthSwap-\u003Ehandle()\n#6 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/KernelPreHandle.php(48): Drupal\\Core\\StackMiddleware\\Session-\u003Ehandle()\n#7 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/modules\/page_cache\/src\/StackMiddleware\/PageCache.php(106): Drupal\\Core\\StackMiddleware\\KernelPreHandle-\u003Ehandle()\n#8 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/modules\/page_cache\/src\/StackMiddleware\/PageCache.php(85): Drupal\\page_cache\\StackMiddleware\\PageCache-\u003Epass()\n#9 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/ReverseProxyMiddleware.php(48): Drupal\\page_cache\\StackMiddleware\\PageCache-\u003Ehandle()\n#10 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/NegotiationMiddleware.php(51): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware-\u003Ehandle()\n#11 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/StackedHttpKernel.php(51): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware-\u003Ehandle()\n#12 \/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/DrupalKernel.php(704): Drupal\\Core\\StackMiddleware\\StackedHttpKernel-\u003Ehandle()\n#13 \/var\/www\/html\/dev\/varbase10c1\/docroot\/index.php(19): Drupal\\Core\\DrupalKernel-\u003Ehandle()\n#14 {main}",
            "trace":[
               {
                  "function":"onException",
                  "class":"Drupal\\jsonapi\\EventSubscriber\\DefaultExceptionSubscriber",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Component\/EventDispatcher\/ContainerAwareEventDispatcher.php",
                  "line":111,
                  "function":"call_user_func"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/vendor\/symfony\/http-kernel\/HttpKernel.php",
                  "line":224,
                  "function":"dispatch",
                  "class":"Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/vendor\/symfony\/http-kernel\/HttpKernel.php",
                  "line":89,
                  "function":"handleThrowable",
                  "class":"Symfony\\Component\\HttpKernel\\HttpKernel",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/modules\/contrib\/simple_oauth\/src\/HttpMiddleware\/BasicAuthSwap.php",
                  "line":54,
                  "function":"handle",
                  "class":"Symfony\\Component\\HttpKernel\\HttpKernel",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/Session.php",
                  "line":58,
                  "function":"handle",
                  "class":"Drupal\\simple_oauth\\HttpMiddleware\\BasicAuthSwap",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/KernelPreHandle.php",
                  "line":48,
                  "function":"handle",
                  "class":"Drupal\\Core\\StackMiddleware\\Session",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/modules\/page_cache\/src\/StackMiddleware\/PageCache.php",
                  "line":106,
                  "function":"handle",
                  "class":"Drupal\\Core\\StackMiddleware\\KernelPreHandle",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/modules\/page_cache\/src\/StackMiddleware\/PageCache.php",
                  "line":85,
                  "function":"pass",
                  "class":"Drupal\\page_cache\\StackMiddleware\\PageCache",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/ReverseProxyMiddleware.php",
                  "line":48,
                  "function":"handle",
                  "class":"Drupal\\page_cache\\StackMiddleware\\PageCache",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/NegotiationMiddleware.php",
                  "line":51,
                  "function":"handle",
                  "class":"Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/StackMiddleware\/StackedHttpKernel.php",
                  "line":51,
                  "function":"handle",
                  "class":"Drupal\\Core\\StackMiddleware\\NegotiationMiddleware",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/core\/lib\/Drupal\/Core\/DrupalKernel.php",
                  "line":704,
                  "function":"handle",
                  "class":"Drupal\\Core\\StackMiddleware\\StackedHttpKernel",
                  "type":"-\u003E"
               },
               {
                  "file":"\/var\/www\/html\/dev\/varbase10c1\/docroot\/index.php",
                  "line":19,
                  "function":"handle",
                  "class":"Drupal\\Core\\DrupalKernel",
                  "type":"-\u003E"
               }
            ]
         }
      }
   ]
}

Proposed resolution

Add the patch fix for 🐛 $request->get may no longer return array as of Symfony 6.0 Fixed

Remaining tasks

  • ✅ File an issue about this project
  • ✅ Addition/Change/Update/Fix to this project
  • ✅ Testing to ensure no regression
  • ➖ Automated unit/functional testing coverage
  • ✅ Developer Documentation support on feature change/addition
    Changed
    Varbase API
  • ✅ User Guide Documentation support on feature change/addition
  • ➖ Accessibility and Readability
  • ✅ Code review from 1 Varbase core team member
  • ✅ Full testing and approval
  • ✅ Credit contributors
  • ✅ Review with the product owner
  • ✅ Update Release Notes and Update Helper on new feature change/addition
  • ✅ Release Varbase 10.0.0-alpha2 , varbase_api-10.0.0-alpha2

Varbase update type

  • ✅ No Update
  • ➖ Optional Update
  • ➖ Forced Update
  • ➖ Forced Update if Unchanged

User interface changes

  • N/A

API changes

After the fix:

{
   "jsonapi":{
      "version":"1.0",
      "meta":{
         "links":{
            "self":{
               "href":"http:\/\/jsonapi.org\/format\/1.0\/"
            }
         }
      }
   },
   "data":[
      {
         "type":"node--landing_page_lb",
         "id":"fefadd5b-d980-4eb9-aa2c-d58f0826bdc1",
         "links":{
            "self":{
               "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/fefadd5b-d980-4eb9-aa2c-d58f0826bdc1?resourceVersion=id%3A3"
            }
         },
         "attributes":{
            "drupal_internal__nid":1,
            "drupal_internal__vid":3,
            "langcode":"en",
            "revision_timestamp":"2023-06-07T10:04:13+00:00",
            "revision_log":"Created homepage node",
            "status":true,
            "title":"Homepage",
            "created":"2023-06-07T10:04:36+00:00",
            "changed":"2023-06-07T10:04:35+00:00",
            "promote":false,
            "sticky":false,
            "default_langcode":true,
            "revision_translation_affected":true,
            "moderation_state":"published",
            "metatag":null,
            "path":{
               "alias":"\/node",
               "pid":99,
               "langcode":"en"
            },
            "rh_action":null,
            "rh_redirect":null,
            "rh_redirect_response":null,
            "rh_redirect_fallback_action":null,
            "publish_on":null,
            "unpublish_on":null,
            "publish_state":"published",
            "unpublish_state":"archived",
            "content_translation_source":"und",
            "content_translation_outdated":false,
            "field_description":null,
            "field_meta_tags":null
         },
         "relationships":{
            "node_type":{
               "data":{
                  "type":"node_type--node_type",
                  "id":"5b09d54d-5e59-4f14-a1b1-53480a5436cb",
                  "meta":{
                     "drupal_internal__target_id":"landing_page_lb"
                  }
               },
               "links":{
                  "related":{
                     "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/fefadd5b-d980-4eb9-aa2c-d58f0826bdc1\/node_type?resourceVersion=id%3A3"
                  },
                  "self":{
                     "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/fefadd5b-d980-4eb9-aa2c-d58f0826bdc1\/relationships\/node_type?resourceVersion=id%3A3"
                  }
               }
            },
            "revision_uid":{
               "data":null,
               "links":{
                  "self":{
                     "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/fefadd5b-d980-4eb9-aa2c-d58f0826bdc1\/relationships\/revision_uid?resourceVersion=id%3A3"
                  }
               }
            },
            "uid":{
               "data":null,
               "links":{
                  "self":{
                     "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/fefadd5b-d980-4eb9-aa2c-d58f0826bdc1\/relationships\/uid?resourceVersion=id%3A3"
                  }
               }
            },
            "layout_selection":{
               "data":null,
               "links":{
                  "self":{
                     "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/fefadd5b-d980-4eb9-aa2c-d58f0826bdc1\/relationships\/layout_selection?resourceVersion=id%3A3"
                  }
               }
            }
         }
      },
      {
         "type":"node--landing_page_lb",
         "id":"e016eb7f-7991-4ead-9248-ef9a3489e57d",
         "links":{
            "self":{
               "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/e016eb7f-7991-4ead-9248-ef9a3489e57d?resourceVersion=id%3A4"
            }
         },
         "attributes":{
            "drupal_internal__nid":2,
            "drupal_internal__vid":4,
            "langcode":"en",
            "revision_timestamp":"2023-06-07T10:04:21+00:00",
            "revision_log":"Create Blog section Landing page (Layout Builder)",
            "status":true,
            "title":"Blog",
            "created":"2023-06-07T10:04:37+00:00",
            "changed":"2023-06-07T10:04:35+00:00",
            "promote":false,
            "sticky":false,
            "default_langcode":true,
            "revision_translation_affected":true,
            "moderation_state":"published",
            "metatag":null,
            "path":{
               "alias":"\/blog",
               "pid":100,
               "langcode":"en"
            },
            "rh_action":null,
            "rh_redirect":null,
            "rh_redirect_response":null,
            "rh_redirect_fallback_action":null,
            "publish_on":null,
            "unpublish_on":null,
            "publish_state":"published",
            "unpublish_state":"archived",
            "content_translation_source":"und",
            "content_translation_outdated":false,
            "field_description":null,
            "field_meta_tags":null
         },
         "relationships":{
            "node_type":{
               "data":{
                  "type":"node_type--node_type",
                  "id":"5b09d54d-5e59-4f14-a1b1-53480a5436cb",
                  "meta":{
                     "drupal_internal__target_id":"landing_page_lb"
                  }
               },
               "links":{
                  "related":{
                     "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/e016eb7f-7991-4ead-9248-ef9a3489e57d\/node_type?resourceVersion=id%3A4"
                  },
                  "self":{
                     "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/e016eb7f-7991-4ead-9248-ef9a3489e57d\/relationships\/node_type?resourceVersion=id%3A4"
                  }
               }
            },
            "revision_uid":{
               "data":null,
               "links":{
                  "self":{
                     "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/e016eb7f-7991-4ead-9248-ef9a3489e57d\/relationships\/revision_uid?resourceVersion=id%3A4"
                  }
               }
            },
            "uid":{
               "data":null,
               "links":{
                  "self":{
                     "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/e016eb7f-7991-4ead-9248-ef9a3489e57d\/relationships\/uid?resourceVersion=id%3A4"
                  }
               }
            },
            "layout_selection":{
               "data":null,
               "links":{
                  "self":{
                     "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb\/e016eb7f-7991-4ead-9248-ef9a3489e57d\/relationships\/layout_selection?resourceVersion=id%3A4"
                  }
               }
            }
         }
      }
   ],
   "links":{
      "self":{
         "href":"http:\/\/localhost\/dev\/varbase10c1\/docroot\/api\/node\/landing_page_lb"
      }
   }
}

Data model changes

  • N/A

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.0

Component

Code

Created by

🇯🇴Jordan Rajab Natshah Jordan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024