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

TransUnitRepository::getAllDomainByLocale problem #423

Open
web-fu opened this issue Sep 6, 2022 · 4 comments
Open

TransUnitRepository::getAllDomainByLocale problem #423

web-fu opened this issue Sep 6, 2022 · 4 comments
Assignees
Labels

Comments

@web-fu
Copy link

web-fu commented Sep 6, 2022

I was trying to refresh the cache via console and I received this error:

Argument 3 passed to Symfony\Bundle\FrameworkBundle\Translation\Translator::addResource() must be of the type string, null given, called in vendor/lexik/translation-bundle/Translation/Translator.php on line 44

After many attempts and some debug, I discovered the problem is caused by this query:

public function getAllDomainsByLocale()
{
    return $this->createQueryBuilder('tu')
        ->select('te.locale, tu.domain')
        ->leftJoin('tu.translations', 'te')
        ->addGroupBy('te.locale')
        ->addGroupBy('tu.domain')
        ->getQuery()
        ->getArrayResult();
}

If the locale column contains any null value the error is triggered.

I don't know if the problem is the leftJoin (maybe should be a normal join) or addResource signature (maybe should accept also null values).

For now I removed the invalid translation_unit rows that caused the problem.

@gansky-alexander
Copy link

Same error.
I am implementing project on SF 6.2, previously it was iplemented on SF3.4. Database for translations was just copied from one project to another.

@bartmcleod bartmcleod added the bug label Jan 26, 2023
@bartmcleod bartmcleod self-assigned this Jan 26, 2023
@martijnboers
Copy link

Have a look at #388 (comment), it solved our issue

@web-fu
Copy link
Author

web-fu commented Feb 24, 2023

As I said, I solved the issue deleting orphan entry from lexik_trans_unit, but I'm not sure it is a "real" solution or just a workaround.
I'll explain how the bug can occur, so maybe it's more clear:

  1. Prepare your view, with your trans term ready ex: {{ 'I am a text to transalte'|trans }}
  2. Go to the /translations endpoint provided by the library
  3. Check for missing translations, but don't translate them
  4. Refresh the cache -> BUG

The missing translation is saved and became an orphan lexik_trans_unit without locale and because
Symfony\Bundle\FrameworkBundle\Translation\Translator::addResource() expect a string (and not a null), it crashes.

The question is: the code shoud exclude orphans or not?

I think "missing translation" should not be an "halting error", just think to a deploy CI that crasches because some translation is missing.

If I would to avoid that an untraslated text to arrive in production:
1 . There should be an explicit option "CI_FAIL_IF_TRANSLATION_MISSING"
2. There should be an Exception, not a type error.

@bartmcleod
Copy link
Collaborator

@web-fu thanks for the clear reproduction steps.

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

No branches or pull requests

4 participants