Hello,

I have a strange problem with node_import.

I want to import a few hundreds nodes of type "Bête" (sorry, french node types -- it means Beast). The content type "Bête" holds 3 cck node references : "Modèle" (Model) , "Zone" (Zone) and "Espèce" (Species), and 2 integers.

All 3 references are "required" and "one of". The faulty reference and another one are "select list". So the faulty reference "Modèle" has the exact same configuration as another one, "Zone".

On the Preview Import page, I had for every row :

An illegal choice has been detected. (caused by the "required" and the following error)
Modèle: this post can't be referenced.

The weird thing is that the array dump showed that the model had actually been read properly and referenced the right node.

The weirder thing is that I tried to proceed with the import. All nodes were rejected *excepted* 7 rows. And these 7 rows reference the only "Modèle" node that already had references to it prior to the import (I had manually created a "Bête" node to test the content type).

So, the import failed for every node that referenced a node that didn't already have a reference to it, but succeed for those that referenced a node that already had a reference to it.

Since the error message was "this post can't be referenced", that would suggest that the content type "Modèle" has to be "bootstrapped" in some way before node_import can programmatically reference it, and the manual "create content" procedure knows how to bootstrap it.

I then removed every node of type "Bête" (the imported type), in order to see if that was the presence of an existing node that enabled the importation of the 7 rows. That wasn't so. My 7 rows were created again, and all other failed.

To confirm the "bootstrapping" theory, I manually created 2 "Bête" nodes referencing 2 other "Modèle" nodes (no error), deleted every "Bête" node, and restarted the import. That didn't work. Only my 7 rows were imported. Even the rows I had created and removed were not imported.

At that point, the only remaining difference between the succeding rows and the failing rows was the fact that the succeding rows's "Modèle" reference had been also created manually, whereas almost every other "Modèle" had been created by node_import. So I created a "Bête" node for of the other "Modèle" nodes that I had created manually (it's becoming hard to follow, isn't it?). It didn't work either.

So I'm really lost here. I'm attaching the last "node import bug report". Basically, my import fails except for 7 rows referencing 1 particular node, and I don't understand why this node can be referenced while all other can't.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Alsciende’s picture

Title: A » This post can't be reference (no multiple)

Sorry about the first post title :(

Alsciende’s picture

Title: This post can't be reference (no multiple) » This post can't be referenced (no multiple)

Ok I get it, thanks to the Devel module.

When checking the input, the first query is

SELECT nid FROM node WHERE nid = -1 OR LOWER(title) = 'batskinbrown01' LIMIT 1

But this query doesn't filter on the type of node, which it could since we know it.

A little further we check the potential reference, with

SELECT n.nid, n.title, n.type AS node_type FROM node n WHERE (n.type = 'modele') ORDER BY n.title, n.type

This time the type is included.

So if you have two nodes with the same title (case-independant !) and the right one is not the first one by nid, then you're screwed.

Suggested fix : check the type on first query. I'm going to try and submit a patch.

Alsciende’s picture

Here is a patch resolving my problem.

The function node_import_check_node_reference now tries to match a reference based upon its possible types (as set in the cck field, multiple types supported).

Please review my patch, it's very short (2 lines).

Alsciende’s picture

Title: This post can't be referenced (no multiple) » Reference nodes titles collide with other nodes
Status: Active » Needs review

I'm renaming the issue to facilitate the search function, and updating the status.

kbk’s picture