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]: multiple types named "element_metadata_item_key_value_pair" #924

Open
klickparkdominik opened this issue Dec 12, 2024 · 6 comments
Open

Comments

@klickparkdominik
Copy link

klickparkdominik commented Dec 12, 2024

Expected behavior

I expect datahub to return valid json for my query.

My example query:

{
  getProductListing(first:10,after:0) {
    totalCount
    edges {
      node {
        id
        applicationRelation { 
          ... on object_applicationArea {
            id
          }
        }
      }
    }
  }
}

Desired example response:

{
  "data": {
    "getProductListing": {
      "totalCount": 162,
      "edges": [
        {
          "node": {
            "id": "257",
            "applicationRelation": [
              {
                "id": "59984"
              }
            ]
          }
        },
[...]

Actual behavior

Instead of the desired response, datahub graphql endpoint throws an error:

{
  "errors": [
    {
      "message": "Schema must contain unique named types but contains multiple types named \"element_metadata_item_key_value_pair\" (see https://webonyx.github.io/graphql-php/type-definitions/#type-registry)."
    }
  ]
}

Keep an eye on the element_metadata_item_key_value_pair part.

Preview panel with error on demo.pimcore.fun 2024.4: Screenshot

Steps to reproduce

See #924 (comment) below.

Additional information

I saw this thread (#836) which is similar to my problem, but the error message is slighly different. Therefore I create a new issue. Probably not related.

This issue suddenly started happening for us today. We never had this problem before. I guess it is related to our Pimcore update. We updated to the latest version 11.5.0 with datahub 1.9.0. We were many versions behind before we applied this update. I think the our last tested and working version was 1.6.3. So my guess is there was a change inbetween these versions.

We have multiple graphql endpoints configured in datahub. Not all graphql endpoints throw this error, just a single one.

I did some digging:

This query does not work -> has spread operator:

{
  getProductListing(first:10,after:0) {
    totalCount
    edges {
      node {
        id
        applicationRelation { 
          ... on object_applicationArea {
            id
          }
        }
      }
    }
  }
}

Does work -> no spread operator:

{
  getProductListing(first:10,after:0) {
    totalCount
    edges {
      node {
        id
      }
    }
  }
}

But I cannot omit these spread operators, because I require that data for our frontend to work.

What I did is: I checked the defined query schema for each object type that is in use in my endpoint. One of my fields seems to cause the issue. When I remove this field from the schema the error is gone.

The broken field in my case is called technicalData and has the type advanced many-to-many object relation.
Maybe the reason is somehow related to the field type? It happens when this field is used for two different object types in the same query schema.

Interesting: You can see the error get's thrown even though I don't use the broken field in my query.

For me the problem appear in dev and production mode.

@klickparkdominik
Copy link
Author

klickparkdominik commented Dec 12, 2024

I am able to reproduce this on https://demo.pimcore.fun/admin 2024.4. It seems to be indeed related to the field type advanced many-to-many object relation.

I will attach some screenshots now, including a step-by-step guide:

  1. Open and login to https://demo.pimcore.fun/admin
  2. Add field with ID test of type advanced many-to-many object relation to BOTH classes OnlineShopOrder and OnlineShopOrderItem
  3. Don't forget to save and apply class settings after making changes.
  4. Update datahub configuration to make use of these two fields in both schema, you can see "test" on the screenshot
  5. Don't forget to save and apply datahub configuration after making changes.
  6. Use the datahub preview panel and execute this query
{
  getOnlineShopOrderListing {
    edges {
      node {
        id
        customer {
          ... on object_Customer {
            id
          }
        }
      }
    }
  }
}
  1. You can see the error happening on the right side
  2. You can work-around the error with these 3 ways:
    • Remove spread customer { [...] operator from query and execute again OR
    • Remove test field from schema OnlineShopOrder and execute again OR
    • Remove test field from schema OnlineShopOrderItems and execute again

@klickparkdominik klickparkdominik changed the title [Bug]: DataHub returns error after Pimcore update [Bug]: multiple types named "element_metadata_item_key_value_pair" Dec 13, 2024
@klickparkdominik
Copy link
Author

klickparkdominik commented Dec 16, 2024

Could it be possible it is related to this change #876 in v1.9.0?

Especially this file: https://github.com/pimcore/data-hub/pull/876/files#diff-d59aa1c799fb7e9a75e486b3dd0089320a9f1c3d4d0f4227a2185221bc30ea6d

Image

@klickparkdominik
Copy link
Author

klickparkdominik commented Dec 16, 2024

Ok, I did test reverting the mentioned change #876 and it fixes the error for me.
Since that change was flagged as "improvement" only, maybe it's OK to revert it?

Unfortunately I have no idea how to make the config-name static without producting my error. I guess that was the intention behind that PR.

@klickparkdominik
Copy link
Author

klickparkdominik commented Dec 16, 2024

Maybe @mattamon can review this? I think there was a discussion for the old PR wether it is a BC or not. It's not that long ago.

CC: @cornedor

@cornedor
Copy link
Contributor

element_metadata_item_key_value_pair should only be registered once, since it is always the same type. I suppose that would be an easy fix (check if it already exists in the registry, and if so, skip registering again)

@klickparkdominik
Copy link
Author

I like the idea and it sounds good, but I don't know how to implement it. If anyone has any tips or even PR for this, I will be happy to test the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants