Problem/Motivation

We are migrating a D6 website with lots of cck nodereferrer fields (not node references - these too, but they are not the issue). cck nodereferrer fields are not supported, but they should just be ignored on migration. Instead, migrating a content type with a nodereferrer field fails:

Migration failed with source plugin exception:

SQLSTATE[42S22]: Column not found: 1054 Unknown column ;field_codb_groups_for_co_; in ;where            [error]
clause': SELECT 0 AS delta
FROM 
{content_type_codb_conscientious_objector} t
WHERE  (field_codb_groups_for_co_ IS NOT NULL ) AND (nid = :db_condition_placeholder_0) AND (vid = :db_condition_placeholder_1); Array
(
    [:db_condition_placeholder_0] =778
    [:db_condition_placeholder_1] =783
)

I tracked it down to the function getCckData(array $field, Row $node) in core/modules/node/src/Plugin/migrate/source/d6/Node.php :

This function does not check whether the table columns array is empty, causing it to add the underscore to the column name (based on the field name), but then nothing. This column does not exist, obviously.
The problem is related to how nodereferrer saves the data in the content_node_field table: it stores an empty array in the column 'db_columns'.

As I understand it, the function first checks for a dedicated table based on the field name, and if that doesn't exist, it selects the table of the respective content type of the field instance.

It then tries to get the titles of the table columns of that table based on the content_node_field table (column db_columns). However, as for nodereferrer fields this contains an empty array, and the function does not check if we really have a value in there.

Steps to reproduce

Proposed resolution

Add a check in the source plugin

    if (isset($query)) {
      $columns = array_keys($field['db_columns']);
      if ( $columns == array() ) {
         return [];
      }

Remaining tasks

Patch
Review
Commit

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Comments

Anonymous’s picture

Andreas Speck created an issue. See original summary.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mikeryan’s picture

Issue tags: +Novice, +migrate-d6-d8

I'm not sure if this was an out-and-out bug in nodereferrer, or if this was a practice in other CCK fields... At any rate, bulletproofing wouldn't hurt:

if (empty($columns)) {
  return [];
}
dimr’s picture

Issue tags: +DevDaysSeville

I am going to work on it in Drupal Dev Days Seville

ebarrera’s picture

Assigned: Unassigned » ebarrera
ebarrera’s picture

Assigned: ebarrera » Unassigned
dimr’s picture

Sorry, but finally I didn't work in this issue. I was working in translation of the User Guide to Spanish.

Charlotte17’s picture

StatusFileSize
new588 bytes

Adding comment#4

Charlotte17’s picture

Status: Active » Needs review

Adding comment#4

mikeryan’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Looks good, but we add a test for this - include a test-only patch which should fail, and a full patch which should succeed.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

RytoEX’s picture

Status: Needs work » Needs review
StatusFileSize
new2.81 KB
new2.23 KB
new2.23 KB

I took a crack at this to try to get it moving. The patch changed slightly after applying and generating due to #2833206: Convert Migrate's cckfield plugins to use the new field plugins, but the patch in #9 still applies okay to 8.4.x.

I added test source_data for nodereferrer for this, but let me know if it's in the wrong place. My local test run of NodeTest failed with "Undefined offset: 0", and the NodeTest passed after applying the full patch attached here. An interdiff against #9 is also attached.

Status: Needs review » Needs work
RytoEX’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

I guess I attached the patches in #13 in the wrong order. Changing the status back to Needs Review since the test failure was expected. Also clearing the Needs tests tag.

maxocub’s picture

Assigned: Unassigned » maxocub

Assigning for review.

maxocub’s picture

Assigned: maxocub » Unassigned
Status: Needs review » Reviewed & tested by the community
Issue tags: -Novice

This looks good, I don't see anything wrong. The test only patch fails as expected. Thanks RytoEX!

catch’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/node/src/Plugin/migrate/source/d6/Node.php
    @@ -270,6 +270,9 @@ protected function getFieldData(array $field, Row $node) {
    +      if (empty($columns)) {
    +        return [];
    +      }
    

    This needs an explanation of why we're just returning empty and not logging anything.

  2. +++ b/core/modules/node/tests/src/Kernel/Plugin/migrate/source/d6/NodeTest.php
    @@ -38,6 +38,18 @@ public function providerSource() {
           ],
    +      [
    +        'field_name' => 'field_test_node_referrer',
    +        'type' => 'nodereferrer',
    +        'global_settings' => 'a:6:{s:14:"referrer_types";a:10:{s:7:"article";i:0;s:7:"company";i:0;s:8:"employee";i:0;s:5:"forum";i:0;s:10:"test_event";i:0;s:9:"test_page";i:0;s:11:"test_planet";i:0;s:10:"test_story";i:0;s:7:"sponsor";i:0;s:5:"story";i:0;}s:15:"referrer_fields";a:1:{s:13:"field_company";i:0;}s:23:"referrer_nodes_per_page";s:1:"0";s:22:"referrer_pager_element";s:1:"0";s:14:"referrer_order";s:9:"TITLE_ASC";s:21:"referrer_translations";i:0;}',
    +        'required' => '0',
    +        'multiple' => '0',
    +        'db_storage' => '1',
    +        'module' => 'nodereferrer',
    +        'db_columns' => 'a:0:{}',
    +        'active' => '1',
    +        'locked' => '0',
    +      ],
    

    Without reading the issue summary I got confused by nodereferrer vs. nodereference. Could we use something more explanatory like 'missing_cck_module'?

jofitz’s picture

Version: 8.4.x-dev » 8.5.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.2 KB
new3.04 KB
  1. Added comment.
  2. Simplified the new test data, removing all references to nodereferrer.
maxocub’s picture

Status: Needs review » Needs work
+++ b/core/modules/node/src/Plugin/migrate/source/d6/Node.php
@@ -270,6 +270,10 @@ protected function getFieldData(array $field, Row $node) {
       $columns = array_keys($field['db_columns']);
+      if (empty($columns)) {
+        // If the field db_columns is empty then there are no values to return.
+        return [];
+      }

I don't find this very clear. I don't think 'db_columns' is a field. Looking at the code I think this snippet is when there's no columns to fetch from a field table.

Also, there's no mention about why we are returning nothing and not logging something.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone credited Anybody.

quietone credited Grevil.

quietone’s picture

Version: 8.9.x-dev » 9.3.x-dev
Issue summary: View changes
Issue tags: +Bug Smash Initiative

Closed #3196867: Pseudo-fields without "db columns", like noderelationships field_backref_* break node migration" as a duplicate. Adding credit for those who helped over there.

Updated IS.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new1.55 KB
new2.2 KB

Updated the patch and made a fail patch.

The last submitted patch, 27: 2784783-27-fail.patch, failed testing. View results

quietone’s picture

Closed #3062062: Ignore nodereferrer field data in D6 Migration as a duplicate, adding credit.

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Great work @all and especially @quiteone!

As we've been using this fix for months now, I'll set this RTBC! :)

alexpott’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 81174ad778 to 9.3.x and 89d028223d to 9.2.x. Thanks!

  • alexpott committed 81174ad on 9.3.x
    Issue #2784783 by RytoEX, quietone, jofitz, Charlotte17, Anybody,...

  • alexpott committed 89d0282 on 9.2.x
    Issue #2784783 by RytoEX, quietone, jofitz, Charlotte17, Anybody,...

Status: Fixed » Closed (fixed)

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