GoogleTagUpgradeManager may fail upgrade for some configurations

Created on 20 September 2023, about 1 year ago
Updated 30 April 2024, 8 months ago

Problem/Motivation

In some specific circumstances, the schema update hook for google_tag.container.*.yml entries will fail with errors such as:

Drupal\google_tag\Migration\GoogleTagMigrateBase::getRequestPathCondition(): Argument #1 ($request_paths) must be of type string, null given, called in /var/www/html/docroot/modules/contrib/google_tag/src/Migration/GoogleTagUpgradeManager.php on line 126

Drupal\google_tag\Migration\GoogleTagMigrateBase::getUserRoleCondition(): Argument #1 ($roles) must be of type array, null given, called in /var/www/html/docroot/modules/contrib/google_tag/src/Migration/GoogleTagUpgradeManager.php on line 145

Steps to reproduce

The observed instance was a D9 production database "dragged" to staging environment in Acquia. As Acquia executes a drush config:import as a post DB copy step, config import was executed before DB updates. (This seems incorrect ... but that's how the config got into this state.)

At this point, the google_tag.container.xxx.yml configurations were loaded in the site, but some values were not populated, and Config API will return a null when they are queried.

When GoogleTagUpgradeManager executes, the following lines will determine that the values are not "" or null, and attempt to treat them as valid values. Replacing each of these checks with a less exact constraint allows the upgrader to handle them correctly.

Proposed resolution

Modify those checks so that the configurations don't get the update applied if they do not have the values set.

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand xurizaemon ลŒtepoti, Aotearoa ๐Ÿ

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

Comments & Activities

  • Issue created by @xurizaemon
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Patch Failed to Apply
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand xurizaemon ลŒtepoti, Aotearoa ๐Ÿ
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand xurizaemon ลŒtepoti, Aotearoa ๐Ÿ
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance Tritof

    Hi,
    I have successfully apply the patch in #2

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States RichardDavies Portland, Oregon

    I encountered the following error when attempting to upgrade from v1.6 to v2.0.2

    Drupal\google_tag\Migration\GoogleTagMigrateBase::getRequestPathCondition(): Argument #1 ($request_paths) must be of type string, null given, called in /app/web/modules/contrib/google_tag/src/Migration/GoogleTagUpgradeManager.php on line 126

    Although this patch allowed me to run the database update without error, it does not appear to have correctly/fully migrated my previous container settings. For example, here is my previous container YAML:

    uuid: 0c9d3f73-ef36-48ab-9c86-28b4cc41bc2b
    langcode: en
    status: true
    dependencies:
      module:
        - webform
    id: employees_portland.gov
    label: 'Employees Portland.gov'
    weight: 0
    container_id: GTM-[REDACTED]
    data_layer: dataLayer
    include_classes: false
    whitelist_classes: |-
      google
      nonGooglePixels
      nonGoogleScripts
      nonGoogleIframes
    blacklist_classes: |-
      customScripts
      customPixels
    include_environment: true
    environment_id: env-3
    environment_token: [REDACTED]
    path_toggle: 'exclude listed'
    path_list: |-
      /admin*
      /batch*
      /clone/*
      /devel/*
      /node/add*
      /node/*/edit
      /node/*/delete
      /node/*/revisions
      /node/*/usage
      /user/*/edit*
      /user/*/cancel*
      /user/*/scheduled*
      /user/*/connected-accounts
      /user/*/submissions
      /group/*/edit
      /group/*/delete
      /group/*/content*
      /group/*/nodes
      /group/*/revisions
      /group/*/members
      /group/*/media*
      /group/*/usage
      /group/*/subgroups
      /group/*/create
      /media/*/edit
      /media/*/delete
      /media/*/usage
      /taxonomy/*/edit
      /taxonomy/*/delete
      /taxonomy/*/usage
    role_toggle: 'exclude listed'
    role_list: {  }
    status_toggle: 'exclude listed'
    status_list: |-
      403
      404
    conditions: {  }

    And here is the new YAML:

    uuid: 0c9d3f73-ef36-48ab-9c86-28b4cc41bc2b
    langcode: en
    status: true
    dependencies: {  }
    id: employees_portland.gov
    label: 'Employees Portland.gov'
    weight: 0
    tag_container_ids:
      - null
    advanced_settings:
      gtm:
        data_layer: dataLayer
        include_classes: false
        allowlist_classes: ''
        blocklist_classes: ''
        include_environment: false
        environment_id: ''
        environment_token: ''
    dimensions_metrics: {  }
    conditions: {  }
    events:
      search: {  }
      webform_purchase: {  }
      login:
        method: CMS
      custom: {  }
      generate_lead:
        value: ''
        currency: ''
      sign_up:
        method: CMS
    

    As you can see, it didn't transfer the container ID, environment, or path exclusion settings.

  • ๐Ÿ‡ธ๐Ÿ‡ฎSlovenia primsi

    Rerolled the patch and added fix for a similar issue in GoogleAnalyticsMigrator. Haven't checked the issue from #5.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    54 pass
  • First commit to issue fork.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia rajeshreeputra Pune

    @RichardDavies I am unable to see the issue described in #5 ๐Ÿ› GoogleTagUpgradeManager may fail upgrade for some configurations Needs work . following step I took to verify:

    • setup drupal 9 latest version codebase.
    • require google_tag 1.6 version as mentioned in #5 ๐Ÿ› GoogleTagUpgradeManager may fail upgrade for some configurations Needs work
    • Install site with minimal profile
    • install google_tag module
    • configure google_tag module
    • update/add environment info, path exclusion, other(as needed)
    • update google_tag to 2.0.2
    • run database update
    • verify google_tag config, all available and upgrade is successful.

    Let me know if I am missing something.

Production build 0.71.5 2024