Problem/Motivation

In #2569069: Replace TranslationWrapper with TranslatableString and deprecate TranslationWrapper we replaced TranslationWrapper with TranslatableMarkup. However, attempting to remove the deprecated TranslationWrapper revealed there are still class references serialized in core database dumps, so it is very likely there are references in databases in the wild as well. Therefore we could not simply remove the class in Drupal 10. So we did #3295421: Update TranslationWrapper deprecation to removal in 11.0.0.

Steps to reproduce

Proposed resolution

Revisit this in Drupal 11.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3269141

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs review
StatusFileSize
new2.33 KB

Status: Needs review » Needs work

The last submitted patch, 2: 3269141-2.patch, failed testing. View results

longwave’s picture

So we still have lots of references to TranslationWrapper in the 9.3.0 dumps used for update tests:

$ fd .gz$|xargs zgrep -c TranslationWrapper|grep -v :0
core/modules/system/tests/fixtures/update/drupal-9.3.0.bare.standard.php.gz:77
core/modules/system/tests/fixtures/update/drupal-9.3.0.filled.standard.php.gz:89

If we have these here, it seems likely that end users with old sites might still have these references in their database? Do we need to figure out where these might exist and write an update hook to try and get rid of them? Otherwise, sites will crash when unserializing any data that still contains this class.

Or maybe the easiest solution is just to leave this in place forever?

andypost’s picture

As I see it's used in serialised data, so it needs update hook to update all data?

sharayurajput made their first commit to this issue’s fork.

longwave’s picture

> As I see it's used in serialised data, so it needs update hook to update all data?

The problem is that we don't know where this could be. Serialised translatable strings could be hiding anywhere, and I'm not sure we could write an update hook to catch them all.

One solution might be just to class_alias TranslatableMarkup to TranslationWrapper and leave it for backward compatibility?

andypost’s picture

Issue tags: +Deprecation Removal
catch’s picture

Title: Remove deprecated Drupal\Core\StringTranslation\TranslationWrapper » Alias deprecated Drupal\Core\StringTranslation\TranslationWrapper to TranslatableMarkup

Agreed with aliasing. If we want to remove the alias, we can try again later. All the cases I could find from manually reviewing the database dump looked like the installed entity definitions in key_value. Opened a follow-up for that specific case at #3284461: Installed entity definitions in key/value use deprecated TranslationWrapper in database dumps, but even once we've done that, we need to keep the alias in the version until after that update has definitely run.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new2.85 KB

This patch deletes the TranslationWrapper class, adds an alias instead, and recycles the legacy test to test the alias.

longwave’s picture

Issue summary: View changes

Updated IS for new approach.

andypost’s picture

@longwave Nice approach! and no longer need to change all dumps

  • catch committed c728e35 on 10.0.x
    Issue #3269141 by longwave, sharayurajput, andypost: Alias deprecated...
catch’s picture

Whoops I just committed this from needs review, misread #16 as an RTBC. But yes this looks good and we can look into removing the alias in Drupal 11 or later.

  • catch committed cadc413 on 10.0.x
    Revert "Issue #3269141 by longwave, sharayurajput, andypost: Alias...
alexpott’s picture

This is kinda tricky because just aliasing the class means that using it will no longer trigger deprecation errors. So in some ways we're in a better place with HEAD. One thing we could try is only making the alias available during update. Do we know which tables are still using it? It is in state because that's going to be trickier to update.

longwave’s picture

Yes it's in state - entity.definitions.installed and entity.update_backup in drupal-9.3.0.bare.standard.php.gz (and the same in filled)

My worry is that these are deliberately clean databases; we can't be sure where else serialized versions of this object may be hiding in real databases that have been around for a long time. Contrib or custom code could have been using this deprecated class any time, at least until it was properly deprecated and that was only in 2020 in #3114239: Properly deprecate \Drupal\Core\StringTranslation\TranslationWrapper. So my thinking here was just to retain this class_alias forever, as reducing it to one line and test is no real maintenance burden and it won't be used except to retain backward compatibility.

alexpott’s picture

+++ b/core/includes/bootstrap.inc
@@ -60,6 +60,11 @@
+/**
+ * Keep backward compatibility for sites with references to TranslationWrapper.
+ */
+class_alias(TranslatableMarkup::class, '\Drupal\Core\StringTranslation\TranslationWrapper', TRUE);

Let's add an example of where this might occur. I think that is a useful justification to maintaining this alias forever.

Another interesting impact of this change is that it means we'll have to load TranslatableMarkup on every request. So that means that we'll have to load \Drupal\Component\Render\FormattableMarkup and \Drupal\Component\Render\MarkupInterface too. So all these things would need to go in the classmap in core/composer.json in order to optimise the cached response autoloading. For me this means we could consider just permanently deprecating TranslationWrapper and being done.

catch’s picture

This is kinda tricky because just aliasing the class means that using it will no longer trigger deprecation errors.

This is true, but if contrib/custom code doesn't have usages now, then I don't think it makes it more likely that new ones will be added. Also don't think the deprecation messages will help to remove serialized content - because all our update tests are @legacy anyway.

catch’s picture

Could we switch TranslationWrapper from @deprecated to @internal with a comment explaining why?

longwave’s picture

Another interesting impact of this change is that it means we'll have to load TranslatableMarkup on every request.

Can we get away with putting the class_alias() line in TranslatableMarkup itself, assuming that at least one bit of TranslatableMarkup will have already been used by the time TranslationWrapper is needed?

alexpott’s picture

Can we get away with putting the class_alias() line in TranslatableMarkup itself, assuming that at least one bit of TranslatableMarkup will have already been used by the time TranslationWrapper is needed?

Unfortunately I don't think we could guarantee that.

andypost’s picture

As I see the usage could only happens in dumps and some serialized caches/data when sites upgraded from 8.x to 10.x but that should not happen when 9.x is not skipped in upgrade process

Maybe better just regenerate dumps without it?

catch’s picture

@andypost I'm not sure that's true. The database fixtures have been created by installing 8.x, running updates, then re-exporting again (up to 9.3.0 so far). This means that the updates have not explicitly removed references to this class during that process.

It's possible that real sites no-longer have the references, but there's not really a way for us to prove this.

catch’s picture

Status: Needs review » Needs work

I keep going around in circles on this issue, I think we should probably do the following:

1. Update the deprecation for removal in drupal:11.0.0 and leave the rest alone for now.

2. Open an issue to try to permanently remove the class if we can - i.e. at least find out why the entity metadata in the dumps never got updated and try to write an update to fix that at least.

catch’s picture

Instead of re-purposing this issue, opened a spin-off to update the deprecation, then this can stay open for the actual removal/aliasing.

#3295421: Update TranslationWrapper deprecation to removal in 11.0.0.

catch’s picture

Wondered if PHP itself had anything for this, and it does, but... not sure we want to go there https://www.php.net/manual/en/var.configuration.php#ini.unserialize-call...

gábor hojtsy’s picture

Title: Alias deprecated Drupal\Core\StringTranslation\TranslationWrapper to TranslatableMarkup » Remove deprecated Drupal\Core\StringTranslation\TranslationWrapper to TranslatableMarkup in Drupal 11
Issue summary: View changes
Status: Needs work » Postponed
Parent issue: #3213895: [META] Remove deprecated classes, methods, procedural functions and code paths outside of deprecated modules on the Drupal 10 branch » #3295574: [meta] Remove deprecated classes, methods, procedural functions and code paths outside of deprecated modules on the Drupal 11 branch

Postponing then to Drupal 11, given #3295421: Update TranslationWrapper deprecation to removal in 11.0.0 landed. Also moving under the Drupal 11 META that I just created.

catch’s picture

Title: Remove deprecated Drupal\Core\StringTranslation\TranslationWrapper to TranslatableMarkup in Drupal 11 » Deprecated Drupal\Core\StringTranslation\TranslationWrapper can't be removed due to serialized PHP in database
Version: 10.0.x-dev » 10.1.x-dev
Status: Postponed » Needs work

Drupal 11 meta seems correct, but we're going to need some kind of 10.x patch before we can actually remove this due to the serialized PHP, so probably more of a 10.1.x task, re-titling now the other issue is in.

ravi.shankar’s picture

StatusFileSize
new2.85 KB
new2.71 KB

Added reroll of patch #14 on Drupal 10.1.x.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Can we have an MR here?

ameymudras’s picture

Assigned: Unassigned » ameymudras

Added a MR and checked for a few more deprecations.

ameymudras’s picture

Assigned: ameymudras » Unassigned
Status: Needs work » Needs review
Issue tags: +DrupalSouth 2024
needs-review-queue-bot’s picture

Status: Needs review » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

andypost’s picture

Related issues: +#3414563: Add new 10.3.x database dump fixtures, without modules deprecated for removal in 11.x
andypost’s picture

Status: Needs work » Needs review

smustgrave changed the visibility of the branch 11.x to hidden.

smustgrave’s picture

Title: Deprecated Drupal\Core\StringTranslation\TranslationWrapper can't be removed due to serialized PHP in database » Remove deprecated Drupal\Core\StringTranslation\TranslationWrapper to TranslatableMarkup in Drupal 11
Status: Needs review » Reviewed & tested by the community

Removal of TranslationWrapper seems fine and didn't cause any issues

Changed the title to #32 as seems to more match what's happening here now.

longwave’s picture

I am not sure that this is a better solution than what we already have. The class alias will be set up on all sites, and we assume that only a very small number of sites actually need this - but we can't get rid of it entirely if it is serialised in unknown places - so isn't it better off left to the autoloader for those sites, but where it won't be loaded at all in the majority case?

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 6a9e301 and pushed to 11.x. Thanks!

  • alexpott committed 67604e09 on 11.x
    Issue #3269141 by ameymudras, longwave, ravi.shankar, sharayurajput,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.