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]: createAsset mutation fails when tags id specified #807

Closed
natted opened this issue Oct 17, 2023 · 4 comments · Fixed by #808
Closed

[Bug]: createAsset mutation fails when tags id specified #807

natted opened this issue Oct 17, 2023 · 4 comments · Fixed by #808
Labels
Milestone

Comments

@natted
Copy link
Contributor

natted commented Oct 17, 2023

Expected behavior

Using createAsset mutation to add image assets including tag identifier, the asset will be created successfully.

Actual behavior

Using createAsset mutation fails with the following error when a tag id is specified with the asset.

{
  "errors": [
    {
      "message": "Internal server error",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "createAsset"
      ],
      "extensions": {
        "debugMessage": "Pimcore\\Model\\Element\\Tag::getById(): Argument #1 ($id) must be of type int, string given, called in /var/www/html/vendor/pimcore/data-hub/src/GraphQL/Traits/ElementTagTrait.php on line 74",
        "file": "/var/www/html/vendor/pimcore/pimcore/models/Element/Tag.php",
        "line": 76,
        "trace": [
          {
            "file": "/var/www/html/vendor/pimcore/data-hub/src/GraphQL/Traits/ElementTagTrait.php",
            "line": 74,
            "call": "Pimcore\\Model\\Element\\Tag::getById('51')"
          },
          {
            "file": "/var/www/html/vendor/pimcore/data-hub/src/GraphQL/Mutation/MutationType.php",
            "line": 1007,
            "call": "Pimcore\\Bundle\\DataHubBundle\\GraphQL\\Mutation\\MutationType::getTagsFromInput(array(1))"
          },
          {
            "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
[SNIPPED]

Steps to reproduce

Use the graphQL explorer / playground to test with a createAsset mutation similar to below

mutation {
  createAsset(
    parentId: 12,
    filename: "12345_image_name.jpg",
    type: "image",
    path: "my-assets",
    input: {
      data: "aaaaaaa-your-image-data"
       metadata: [
        { name: "Title", type: "input", data: "YOUR IMAGE NAME" },
        { name: "Category", type: "input", data: "Cars" },
        { name: "Segment", type: "input", data: "Fast Cars" },
        { name: "Image Source", type: "input", data: "F360" },
        { name: "License Rights", type: "input", data: "Open" },
        { name: "Description", type: "input", data: "Image Description" },
        { name: "Image Alt", type: "input", data: "" }
      ],
      tags:[
        { id: 51 }
      ]
      
    }) {
    success
    message
  }
}
@natted natted added the Bug label Oct 17, 2023
@natted
Copy link
Contributor Author

natted commented Oct 17, 2023

The issue only occurs when tag id is specified (appears due to strict typing).
If we supply tag as path instead of id, createAsset works.

As a workaround - I updated line 74 within ElementTagTrait.php as follows:
Not sure if it's the right solution but can add PR if useful

  $tagId = intval($tag_input['id']);
  $tag = Tag::getById($tagId);

@mattamon
Copy link
Contributor

The issue only occurs when tag id is specified (appears due to strict typing). If we supply tag as path instead of id, createAsset works.

As a workaround - I updated line 74 within ElementTagTrait.php as follows: Not sure if it's the right solution but can add PR if useful

  $tagId = intval($tag_input['id']);
  $tag = Tag::getById($tagId);

Hey @natted,

thank you for raising an issue for this. We would be happy about a PR.
A simple cast should be enough though. No need for intval since we do not need a different base.

  $tag = Tag::getById((int)$tag_input['id']);

Thank you and cheers!

@dvesh3
Copy link
Contributor

dvesh3 commented Oct 30, 2023

@kingjia90 should we close this as the linked PR is merged?

@kingjia90
Copy link
Contributor

Fixed by #808

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.

4 participants