Problem/Motivation

static is evil :)

That pattern causes the EntityTranslationHandlerFactory instance to persist between test methods of a test.

See https://www.drupal.org/node/2674592#comment-10892412, I had test fails that I didn't have locally, turns out the difference was that I had a very old entity_translation version locally that didn't have that static cache yet.

Which resulted that the code ended up using handlers from a previous run (as the entities had the same ID's), and then the language returned by entity_language() doesn't return what you'd expect.

Proposed resolution

Use drupal_static(). Yes, it's weird, but that's the only option.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new1.01 KB
douggreen’s picture

This problem also causes a memory leak, because entity translation holds onto a copy of the entity after resetCache() and drupal_static_reset().

stefanos.petrakis’s picture

So, after this patch is applied, one could call drupal_static_reset('EntityTranslationHandlerFactory') to make sure no out-dated or irrelevant object is kept in memory, as in the case of running aut. tests.

I am considering making this part of the class's interface as in:

  /**
   * Resets the stored singleton instance.
   */
  public static function resetInstance() {
    self::$instance = new EntityTranslationHandlerFactory();
  }