Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Creating asset doesn't work #791

Closed
brusch opened this issue Aug 23, 2023 · 5 comments · Fixed by #798
Closed

[Bug]: Creating asset doesn't work #791

brusch opened this issue Aug 23, 2023 · 5 comments · Fixed by #798
Assignees
Labels
Milestone

Comments

@brusch
Copy link
Member

brusch commented Aug 23, 2023

Expected behavior

Thw following mutation throws an error:

mutation {
  createAsset(parentId: 1, filename: "foo", type: "text") {
    success
    message
  }
}

Error message:

{
  "errors": [
    {
      "message": "Internal server error",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "createAsset"
      ],
      "extensions": {
        "debugMessage": "Pimcore\\Model\\Element\\Service::isValidKey(): Argument #1 ($key) must be of type string, null given, called in /var/www/html/dev/pimcore/pimcore/models/Asset.php on line 562",
        "file": "/var/www/html/dev/pimcore/pimcore/models/Element/Service.php",
        "line": 947,
        "trace": [
          {
            "file": "/var/www/html/dev/pimcore/pimcore/models/Asset.php",
            "line": 562,
            "call": "Pimcore\\Model\\Element\\Service::isValidKey(null, 'asset')"
          },
          {
            "file": "/var/www/html/dev/pimcore/pimcore/models/Asset.php",
            "line": 434,
            "call": "Pimcore\\Model\\Asset::correctPath()"
          },
          {
            "file": "/var/www/html/vendor/pimcore/data-hub/src/GraphQL/Mutation/MutationType.php",
            "line": 1572,
            "call": "Pimcore\\Model\\Asset::save()"
          },
          {
            "file": "/var/www/html/vendor/pimcore/data-hub/src/GraphQL/Mutation/MutationType.php",
            "line": 1023,
            "call": "Pimcore\\Bundle\\DataHubBundle\\GraphQL\\Mutation\\MutationType::saveElement(instance of Pimcore\\Model\\Asset\\Text, array(3))"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
            "line": 714,
            "call": "Pimcore\\Bundle\\DataHubBundle\\GraphQL\\Mutation\\MutationType::Pimcore\\Bundle\\DataHubBundle\\GraphQL\\Mutation\\{closure}(array(0), array(3), array(2), instance of GraphQL\\Type\\Definition\\ResolveInfo)"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
            "line": 631,
            "call": "GraphQL\\Executor\\ReferenceExecutor::resolveFieldValueOrError(instance of GraphQL\\Type\\Definition\\FieldDefinition, instance of GraphQL\\Language\\AST\\FieldNode, instance of Closure, array(0), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(2))"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
            "line": 541,
            "call": "GraphQL\\Executor\\ReferenceExecutor::resolveField(GraphQLType: Mutations, array(0), instance of ArrayObject(1), array(1), array(2))"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
            "line": 949,
            "call": "GraphQL\\Executor\\ReferenceExecutor::GraphQL\\Executor\\{closure}(array(0), 'createAsset')"
          },
          {
            "call": "GraphQL\\Executor\\ReferenceExecutor::GraphQL\\Executor\\{closure}(array(0), 'createAsset')"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
            "line": 941,
            "function": "array_reduce(array(1), instance of Closure, array(0))"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
            "line": 533,
            "call": "GraphQL\\Executor\\ReferenceExecutor::promiseReduce(array(1), instance of Closure, array(0))"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
            "line": 297,
            "call": "GraphQL\\Executor\\ReferenceExecutor::executeFieldsSerially(GraphQLType: Mutations, array(0), array(0), instance of ArrayObject(1), array(2))"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
            "line": 237,
            "call": "GraphQL\\Executor\\ReferenceExecutor::executeOperation(instance of GraphQL\\Language\\AST\\OperationDefinitionNode, array(0))"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/Executor.php",
            "line": 159,
            "call": "GraphQL\\Executor\\ReferenceExecutor::doExecute()"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/GraphQL.php",
            "line": 162,
            "call": "GraphQL\\Executor\\Executor::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, instance of GraphQL\\Language\\AST\\DocumentNode, array(0), array(2), array(0), null, null)"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/GraphQL.php",
            "line": 96,
            "call": "GraphQL\\GraphQL::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, 'mutation {\n  createAsset(parentId: 1, filename: \"foo\", type: \"text\") {\n    success\n    message\n  }\n}\n', array(0), array(2), array(0), null, null, null)"
          },
          {
            "file": "/var/www/html/vendor/pimcore/data-hub/src/Controller/WebserviceController.php",
            "line": 203,
            "call": "GraphQL\\GraphQL::executeQuery(instance of GraphQL\\Type\\Schema, 'mutation {\n  createAsset(parentId: 1, filename: \"foo\", type: \"text\") {\n    success\n    message\n  }\n}\n', array(0), array(2), array(0), null, null, null)"
          },
          {
            "file": "/var/www/html/vendor/symfony/http-kernel/HttpKernel.php",
            "line": 166,
            "call": "Pimcore\\Bundle\\DataHubBundle\\Controller\\WebserviceController::webonyxAction(instance of Pimcore\\Bundle\\DataHubBundle\\GraphQL\\Service, instance of Pimcore\\Localization\\LocaleService, instance of Pimcore\\Model\\Factory, instance of Symfony\\Component\\HttpFoundation\\Request, instance of Pimcore\\Helper\\LongRunningHelper)"
          },
          {
            "file": "/var/www/html/vendor/symfony/http-kernel/HttpKernel.php",
            "line": 74,
            "call": "Symfony\\Component\\HttpKernel\\HttpKernel::handleRaw(instance of Symfony\\Component\\HttpFoundation\\Request, 1)"
          },
          {
            "file": "/var/www/html/vendor/symfony/http-kernel/Kernel.php",
            "line": 197,
            "call": "Symfony\\Component\\HttpKernel\\HttpKernel::handle(instance of Symfony\\Component\\HttpFoundation\\Request, 1, true)"
          },
          {
            "file": "/var/www/html/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php",
            "line": 35,
            "call": "Symfony\\Component\\HttpKernel\\Kernel::handle(instance of Symfony\\Component\\HttpFoundation\\Request)"
          },
          {
            "file": "/var/www/html/vendor/autoload_runtime.php",
            "line": 29,
            "call": "Symfony\\Component\\Runtime\\Runner\\Symfony\\HttpKernelRunner::run()"
          },
          {
            "file": "/var/www/html/public/index.php",
            "line": 20,
            "function": "require_once('/var/www/html/vendor/autoload_runtime.php')"
          }
        ]
      }
    }
  ],
  "data": {
    "createAsset": null
  }
}

Actual behavior

Throws an error

Steps to reproduce

Run the above query

@brusch brusch added the Bug label Aug 23, 2023
@dvesh3
Copy link
Contributor

dvesh3 commented Aug 23, 2023

mutation {
  createAsset(
    parentId: 1,
    filename: "foo1",
    type: "text",
    input: {
      filename: "foo",
      parentId: 1,
      data: "ewogICAgImZpZWxkY29sbGVjdGlvbiI6IFsKICAgICAgICB7CiAgICAgICAgICAgICJwYXJlbn...."
    }) {
    success
    message
  }
}

When providing input, it works. However it should not expect duplicate info in the input e.g. filename, parentId etc.

@brusch
Copy link
Member Author

brusch commented Aug 23, 2023

@dvesh3 thakns for clarifying, but it shouldn't be necessary to define filename twice, since the argument filename in createAsset() is required, this value should be used, and filename within input should be optional imho. WDYT?

@brusch
Copy link
Member Author

brusch commented Aug 23, 2023

Also the docs are wrong in this case 😊
https://pimcore.com/docs/platform/Datahub/GraphQL/Mutation/Asset_Mutations

@dvesh3
Copy link
Contributor

dvesh3 commented Aug 23, 2023

@dvesh3 thakns for clarifying, but it shouldn't be necessary to define filename twice, since the argument filename in createAsset() is required, this value should be used, and filename within input should be optional imho. WDYT?

@brusch yes, that's what i meant by "However it should not expect duplicate info in the input e.g. filename, parentId etc." 😊

@dvesh3 dvesh3 added this to the 1.6.4 milestone Aug 29, 2023
@dvesh3 dvesh3 self-assigned this Sep 13, 2023
dvesh3 added a commit that referenced this issue Sep 13, 2023
robertSt7 pushed a commit that referenced this issue Sep 14, 2023
…ename (#798)

* [Mutation] Fix CreateAsset mutation not considering required field filename - resolves #791

* [Mutation] Add assets docs

* [Mutation] Fix asset delete by id or fullpath

* Apply php-cs-fixer changes

---------

Co-authored-by: dvesh3 <[email protected]>
@dvesh3
Copy link
Contributor

dvesh3 commented Sep 14, 2023

Fixed by #798

@dvesh3 dvesh3 closed this as completed Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants