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

Issue fork google_tag-3388487

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

xurizaemon created an issue. See original summary.

xurizaemon’s picture

Status: Active » Needs review
StatusFileSize
new1.98 KB
xurizaemon’s picture

Issue summary: View changes
tritof’s picture

Hi,
I have successfully apply the patch in #2
Drupal 10.1.5 / PHP 8.1

richarddavies’s picture

Status: Needs review » Needs work

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.

primsi’s picture

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

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

rajeshreeputra’s picture

@RichardDavies I am unable to see the issue described in #5. following step I took to verify:

  • setup drupal 9 latest version codebase.
  • require google_tag 1.6 version as mentioned in #5
  • 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 version as mentioned in #5
  • run database update
  • verify google_tag config, all available and upgrade is successful.

Let me know if I am missing something.

berliner’s picture

I have run into this on a D10 site. Though I don't have time to look into exactly how this issue got triggered, I can confirm that the patch addresses the problem and makes the error go away.

falco010’s picture

Also got the following error when upgrading from 1.8.0 to 2.0.8:

>  [error]  Drupal\google_tag\Migration\GoogleTagMigrateBase::getUserRoleCondition(): Argument #1 ($roles) must be of type array, null given, called in /var/www/html/web/modules/contrib/google_tag/src/Migration/GoogleTagUpgradeManager.php on line 147
>  [error]  Update failed: google_tag_update_8201
 [error]  Update aborted by: google_tag_update_8201
 [error]  Finished performing updates.

Can confirm that patch #6 solved the errors

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

japerry’s picture

Status: Needs work » Fixed

Confirmed the bug on 2.0.x. It happens when `drush config:import` runs before `drush updatedb` on a site with 1.x data. The import saves the containers through the 2.x entity class, which strips the 1.x keys, so google_tag_update_8201 gets NULLs. That's why a plain 1.x to 2.x updb doesn't reproduce it.

Patch #6 stops the crash, but as #5 showed, the container still ends up with `tag_container_ids: [null]` and GTM settings under an empty ID. MR !155 replaces it:

  • The upgrade manager and the Google Analytics migrator type-check the legacy path, status and role values before converting them.
  • A container with no 1.x container ID skips the tag ID and GTM settings conversion and logs a warning naming the container. Its conditions and default events are still upgraded.
  • Added two TagContainerUpdateTest cases: unset path/role/status lists, and a container stripped by config import. Both fail on 2.0.x with the reported TypeError.

If you've hit this, re-enter the container's tag ID and settings. To avoid it, run database updates before config import (`drush deploy` does it in the right order).

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • japerry committed c037c763 on 2.0.x
    fix: #3388487 Upgrade 1.x containers correctly when their config was...

Status: Fixed » Closed (fixed)

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