Inifite loop in ai_translate entity reference with content

Created on 14 October 2024, about 1 month ago

Problem/Motivation

When using ai_translate it can end up with infinite loop when trying to translate a content with entity reference that reference content.

Steps to reproduce

- Create a node that has a field that reference this same node.
- In ai_translate configuration : /admin/config/ai/ai_translate check "content" under the "Entity reference translation" config.
- Translate this node using the "Translate using AI" link.
- It will generate an infinite loop.

The infinite loop is due to the fact that in the file web/modules/contrib/ai/modules/ai_translate/src/Plugin/FieldTextExtractor/ReferenceFieldExtractor.php , the extract() method will dive recursively in all referenced entity of the node, meaning that if the node reference itself, or if at some point in the recursive, we come back to the original node, it will create an infinite loop.

Proposed resolution

Multiple ideas :
- Limit the recursive to only translate the content referenced in the original node. (depth : 1)
- Limite the recursive to a max depth set in config
- Put the already translated entities in an array to make sure we only try to translate it once ( not big fan of this one, we could translate the entire website without knowing it if there is a lot of reference in the nodes).

🐛 Bug report
Status

Active

Version

1.0

Component

Other Submodules

Created by

🇧🇪Belgium arwillame

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024