File records, files themselves lost in translation

Created on 22 December 2015, almost 9 years ago
Updated 12 October 2023, about 1 year ago

Problem/Motivation

In a project we discovered a potential bug regarding file translations:

* 3 languages: german, french and italian
* base language german ( same error with english base language )

Steps to reproduce :
* enable all language modules
* make project 3 lingual
* create a content type with a file field ( not image )
* make this content type translatable ( including the file )
* create a german base one and translate it into french ( also replace the file )
* translate it also into italian ( also replacing the file )
* edit the german node again and you see that the german file is gone

Discoveries :
* While the initial translation into french works, the file will be removed from the file_usage table. The status of the first file in file_managed will be set to 0
* The french translation file will be created using the german langcode "de" in the file_managed table ( perhaps thats correct but its strange )
* The translation into italian then even deletes the german file in the file_managed table
* If you add the file again to the german node after it got deleted it works like expected.

* Additional problem: after adding one translation and then deleting that again, the file you uploaded from the translation is not removed from the file_managed and file_usage table, but it is from the file system ..

There is data loss in this issue.

Proposed resolution

This makes two changes to fix the mentioned bugs:

* The FileFieldItemList class should never look at anything but the current translation. There are only old values if the translation already existed.
* We have to call delete() on field items that are part of deleted translations, so that they work as expected. We've already seen this problem in other issues, e.g. #2539634: PathItem::delete() never runs because the path field type is a computed field in disguise β†’

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

8.0 ⚰️

Component
File moduleΒ  β†’

Last updated about 7 hours ago

Created by

πŸ‡¨πŸ‡­Switzerland yobottehg Basel

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡³China lawxen

    I'm working on a project that someone else did,An error was encountered on commerce checkout completion, what I did is just add an file field(multi value) to order type.

    Error mesaage:

    The website encountered an unexpected error. Please try again later.
    Error: Call to a member function hasTranslation() on null in Drupal\file\Plugin\Field\FieldType\FileFieldItemList->postSave() (line 54 of core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php).
    Drupal\file\Plugin\Field\FieldType\FileFieldItemList->postSave(1)
    call_user_func_array(Array, Array) (Line: 938)
    Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldMethod('postSave', Object, 1) (Line: 970)
    Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldPostSave(Object, 1) (Line: 896)
    Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object) (Line: 56)
    Drupal\commerce\CommerceContentEntityStorage->invokeHook('update', Object) (Line: 64)
    Drupal\commerce_order\OrderStorage->invokeHook('update', Object) (Line: 598)
    Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, 1) (Line: 781)
    Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, 1) (Line: 523)
    Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 804)
    Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
    Drupal\Core\Entity\EntityBase->save() (Line: 429)
    Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowBase->submitForm(Array, Object) (Line: 614)
    Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowWithPanesBase->submitForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 114)
    Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
    Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
    Drupal\Core\Form\FormBuilder->processForm('commerce_checkout_flow_multistep_default', Array, Object) (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 224)
    Drupal\Core\Form\FormBuilder->getForm(Object, 'review') (Line: 143)
    Drupal\commerce_checkout\Controller\CheckoutController->formPage(Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 38)
    Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    

    I haven't got which cause this problem, but the code change of this issue's commit has some flaw here:
    if ($original->hasTranslation($langcode))
    It didn't check whether the $original is null.

  • πŸ‡¨πŸ‡³China lawxen

    I have create a new issue for it

Production build 0.71.5 2024