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

[GraphQl] Exception are not translated to store scope. #31351

Closed
1 of 5 tasks
Hexmage opened this issue Dec 18, 2020 · 31 comments · Fixed by #32953
Closed
1 of 5 tasks

[GraphQl] Exception are not translated to store scope. #31351

Hexmage opened this issue Dec 18, 2020 · 31 comments · Fixed by #32953
Labels
Area: Cart & Checkout Component: GraphQL GraphQL Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Project: GraphQL Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S1 Affects critical data or functionality and forces users to employ a workaround.

Comments

@Hexmage
Copy link

Hexmage commented Dec 18, 2020

Preconditions (*)

Reproduced on

  1. Magento 2.3.5-p2
  2. Magento 2.4.1

Steps to reproduce (*)

  1. Set the locale of a store to anything but en_US.
  2. Create a translation file/database entry with one of the translatable exception strings (eg: 'currentPage value must be greater than 0.' to 'This text is translated')
  3. Make a GraphQl request that will cause the exception to trigger with the Store header for the store set in 1.
query productList{
    products( currentPage: 0) {
        items {
            id
            name
        }
    }
}

Expected result (*)

{
    "errors": [
        {
            "message": "This text is translated.",
            "extensions": {
                "category": "graphql-input"
            },
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "products"
            ]
        }
    ],
    "data": {
        "products": null
    }
}

Actual result (*)

{
    "errors": [
        {
            "message": "currentPage value must be greater than 0.",
            "extensions": {
                "category": "graphql-input"
            },
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "products"
            ]
        }
    ],
    "data": {
        "products": null
    }
}

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Dec 18, 2020

Hi @Hexmage. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@t-heuser
Copy link

Having the same issue, can confirm for Magento 2.4.1.

@t-heuser
Copy link

@ReggieTe
Copy link

I'm experiencing the same issue on Magento 2.3.4 and the patch on https://stackoverflow.com/questions/61770306/while-working-with-the-magento-2-graphql-it-seems-that-the-string-translation-do seems not to be working

@shikhamis11 shikhamis11 self-assigned this Jan 28, 2021
@m2-assistant
Copy link

m2-assistant bot commented Jan 28, 2021

Hi @shikhamis11. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@shikhamis11 shikhamis11 added the Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch label Jan 28, 2021
@Hexmage
Copy link
Author

Hexmage commented Mar 8, 2021

I'm experiencing the same issue on Magento 2.3.4 and the patch on https://stackoverflow.com/questions/61770306/while-working-with-the-magento-2-graphql-it-seems-that-the-string-translation-do seems not to be working

It only seems to translate to the default store locale so if you have multiple locales it breaks.

@Hexmage
Copy link
Author

Hexmage commented Mar 8, 2021

<?php

namespace Vender\GraphQlExceptionMessageFix\Plugin\Controller;

use Magento\Framework\App\Area;
use Magento\Framework\App\AreaList;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\State;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\TranslateInterface;
use Magento\GraphQl\Controller\GraphQl;
use Magento\Store\Model\StoreManagerInterface;

class GraphQlPlugin
{
    /** @var AreaList $areaList */
    private $areaList;

    /** @var State $appState */
    private $appState;
    /**
     * @var StoreManagerInterface
     */
    private $storeManager;
    /**
     * @var ResolverInterface
     */
    private $localeResolver;

    public function __construct(
        AreaList $areaList,
        State $appState,
        TranslateInterface $translation,
        ResolverInterface $localeResolver,
        StoreManagerInterface $storeManager
    ) {
        $this->areaList = $areaList;
        $this->appState = $appState;
        $this->translation = $translation;
        $this->localeResolver = $localeResolver;
        $this->storeManager = $storeManager;
    }

    public function beforeDispatch(GraphQl $subject, RequestInterface $request)
    {
        $area = $this->areaList->getArea($this->appState->getAreaCode());
        $storeIdOrCode = $request->getHeader('store') ?: 0;
        $locale = $this->storeManager->getStore($storeIdOrCode)->getConfig('general/locale/code');
        $this->localeResolver->setLocale($locale);
        $this->translation->setLocale($locale);
        $area->load(Area::PART_TRANSLATE);
    }
}

Working version of the plugin at https://stackoverflow.com/questions/61770306/while-working-with-the-magento-2-graphql-it-seems-that-the-string-translation-do

@rikwillems
Copy link
Contributor

@Hexmage when I patch the GraphQL controller the translation works at store level too. In that case there is no need to determine the correct language.

@Hexmage
Copy link
Author

Hexmage commented Mar 24, 2021

@rikwillems I determine the correct language because it can be different for each storeview.

The original fix only looked at the locale set at the highest level. So if you had multiple storeviews with different locales it didn't work.

@ihor-sviziev ihor-sviziev added the Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. label Mar 24, 2021
@ihor-sviziev
Copy link
Contributor

@sidolov @sivaschenko seems like quite an important issue for single-page applications, like PWA, or by using GraphQL on the frontend and showing exceptions to users.
Let's set priority to p2 or even p1.

@shikhamis11
Copy link
Member

shikhamis11 commented Mar 24, 2021

@ihor-sviziev I agree. It's quite an important bug since multi-store and multi language features are already there at pwa studio with the release of 2.4.2. This should be addressed soon.

@gabrieldagama
Copy link
Contributor

Error messages may be changed to error codes, and PWA and any other application consuming the GraphQL API should perform the translation on the frontend application, similar issue with #27600

Cc. @cpartica

@Hexmage
Copy link
Author

Hexmage commented Mar 25, 2021

@gabrieldagama
This feels like a waste of having the entire translation functionality in Magento. Adding Error Codes is fine because you might want to do something different based on the error code. But seeing as all other endpoints (soap, rest, the html frontend) do translate their output based on the store scope it would be weird that only graphql doesn't do this.

And by putting the burden of translations on the frontend application, you'll increase it's size which you are trying to prevent especially if it will be running client side.

@rikwillems
Copy link
Contributor

In my case I'm reading the cart/quote items that have custom made options. The labels of these options were not translated which doesn't make any sense, also not regarding PWA. My fix is:

Load the translations when the GraphQL controller is dispatched.
===================================================================
--- Controller/GraphQl.php
+++ Controller/GraphQl.php
@@ -7,6 +7,7 @@

 namespace Magento\GraphQl\Controller;

+use Magento\Framework\App\Area;
 use Magento\Framework\App\FrontControllerInterface;
 use Magento\Framework\App\Request\Http;
 use Magento\Framework\App\RequestInterface;
@@ -89,6 +90,9 @@
      */
     private $contextFactory;

+    /** @var \Magento\Framework\App\State $appState */
+    private $appState;
+
     /**
      * @param Response $response
      * @param SchemaGeneratorInterface $schemaGenerator
@@ -114,7 +118,8 @@
         QueryFields $queryFields,
         JsonFactory $jsonFactory = null,
         HttpResponse $httpResponse = null,
-        ContextFactoryInterface $contextFactory = null
+        ContextFactoryInterface $contextFactory = null,
+        \Magento\Framework\App\AreaList $areaList
     ) {
         $this->response = $response;
         $this->schemaGenerator = $schemaGenerator;
@@ -127,6 +132,7 @@
         $this->jsonFactory = $jsonFactory ?: ObjectManager::getInstance()->get(JsonFactory::class);
         $this->httpResponse = $httpResponse ?: ObjectManager::getInstance()->get(HttpResponse::class);
         $this->contextFactory = $contextFactory ?: ObjectManager::getInstance()->get(ContextFactoryInterface::class);
+        $this->areaList = $areaList;
     }

     /**
@@ -138,6 +144,8 @@
      */
     public function dispatch(RequestInterface $request) : ResponseInterface
     {
+        $this->areaList->getArea(Area::AREA_GRAPHQL)->load(Area::PART_TRANSLATE);
+
         $statusCode = 200;
         $jsonResult = $this->jsonFactory->create();
         try {

@cpartica
Copy link
Contributor

Error messages may be changed to error codes, and PWA and any other application consuming the GraphQL API should perform the translation on the frontend application, similar issue with #27600

Cc. @cpartica

@engcom-Alfa engcom-Alfa added Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch and removed Progress: PR in progress labels Dec 17, 2021
@engcom-Alfa engcom-Alfa added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Dec 17, 2021
@github-jira-sync-bot
Copy link

❌ Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.magento.com/browse/AC-1946

@engcom-Alfa engcom-Alfa added the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Dec 17, 2021
@github-jira-sync-bot
Copy link

❌ Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.magento.com/browse/AC-1946

1 similar comment
@github-jira-sync-bot
Copy link

❌ Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.magento.com/browse/AC-1946

@slackerzz
Copy link
Member

slackerzz commented Feb 8, 2022

Is this fixed? In which magento version?

@cpartica
Copy link
Contributor

cpartica commented Feb 8, 2022

2.4.4 - you just have to wait for it
Back in December we diverged branches for 2.4.4 and 2.4-develop for regression purposes and for ~ 3 months this process is invisible to the main branch
You will see the PR automerged when 2.4.4 is released

@engcom-November
Copy link
Contributor

Hi,
This issue got fixed in the scope of the internal Jira ticket AC-1946 by the internal team

Related commits: https://github.com/magento/magento2/search?q=AC-1946&type=commits
Based on Jira, target version is 2.4.4
Thank you.

@zakdma
Copy link
Contributor

zakdma commented Apr 24, 2024

This issue is still present for 2.4.7. I see changes but they does not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Cart & Checkout Component: GraphQL GraphQL Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Project: GraphQL Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S1 Affects critical data or functionality and forces users to employ a workaround.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.