you should not feed gizmo after midnight and you should not call taxonomy_term_save() with one of the $term->parent[] values being equal to $term->tid. this will cause what looks like a memory heap problem and httpd process terminating (fairly recent xampp (with php5.3) on windows 7).

suggestion: have a handler for the case when a $term->parent value is the same as the $term->tid value, including something like drupal_set_message('hey there, the taxonomy term graph cannot have looped edges').

aside: can someone please explain why inside of the else on line 615 of taxonomy.module, for an update $op, the taxonomy_term_data record is *deleted*? sure, a new record is inserted, but why not have a database operation that does what the $op ingenuously purports to do? if not for that, what about for the sake of the transaction? as far as i can tell, there's no transaction to roll back if for some reason that delete operation works but the insert fails... leaving the database with an integrity issue.

another aside: discovered this issue when investigating an issue with NAT (Node Auto Term) http://drupal.org/node/1515484#comment-5828924. nat-7.x-1.x-dev (master pull up to commit 5f745634d623e97e7bc6c0023fbb3551745ff8c0), nat.module::_nat_get_term_hierarchies() returns a term reference value as a parent tid of the term being referenced. the term reference value can be the same as the NAT tid value.

Comments

jaypark’s picture

oh yeah... this issue is very easy to reproduce; no need to install NAT.

$tid = 1 //or some other tid for existing term
$term=taxonomy_term_load($tid);
$term->parent = array(0 => $tid);
taxonomy_term_save($term);
filijonka’s picture

Status: Active » Postponed (maintainer needs more info)

how did you get into this situation at all: $term->parent[] values being equal to $term->tid?

jaypark’s picture

Title: taxonomy_term_save() pathauto invocation results in fatal error if parent tid is the same as the tid of the term being saved. » function taxonomy_term_save() fails if parent tid is the same as the tid of the term being saved.
Priority: Critical » Normal
Status: Needs work » Postponed (maintainer needs more info)

because of the fundamental flaw in the way the NAT module was designed. it uses a term reference field to set where the auto-created term should be in the hierarchy. ie, NAT points the node's term reference field to what should be selected in the auto-created term's relationship field - the *parent* of the auto-created term.

this flaw becomes apparent if, say, you run taxonomy_select_nodes($tid) on the auto-created term->tid.

so i'd attempted to automatically set the term reference field value to the auto-created-term. with NAT's design, this sets the referenced term's parent to itself.

instead, NAT uses a table to define the node-autoterm relationship(!) - which is the whole point of having a term reference field, no?

anyway.. a deeper dive revealed that this issue is not with drupal core... it's with a taxonomy module invocation of pathauto, which throws a fatal error when a term's parent tid is the term's tid itself.

i can think of a few reasons why a term's parent tid can be its own tid, ie, why a module should allow for an edge loop.

jaypark’s picture

Title: function taxonomy_term_save() fails if parent tid is the same as the tid of the term being saved. » taxonomy_term_save() pathauto invocation results in fatal error if parent tid is the same as the tid of the term being saved.
Project: Drupal core » Pathauto
Version: 7.12 » 7.x-1.0-rc2
Component: taxonomy.module » Code
jaypark’s picture

Priority: Normal » Critical
Status: Postponed (maintainer needs more info) » Needs work

changed status: needs work. maintainers, please look at what pathauto lines run with term save invocation.

changed priority: critical. likely a recursion issue, but not the normal kind. this one caused (reproducible) memory heap and httpd termination errors.

Dave Reid’s picture

Title: function taxonomy_term_save() fails if parent tid is the same as the tid of the term being saved. » taxonomy_term_save() pathauto invocation results in fatal error if parent tid is the same as the tid of the term being saved.
Version: 7.x-1.0-rc2 » 7.x-1.x-dev
Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Active

I'm still not convinced this isn't NAT's problem with putting bad data into the core taxonomy tables. Now we have to check wherever in core and contrib we refer to parent terms to check for recursion?

Downgrading since this only affects a small portion of users.

-otto-’s picture

Oops, added a comment here, wrong tab, sorry.

davery’s picture

I have a possibly related issue. I get timeouts when using taxonomy_term_save on terms in a zipcode vocab containing every zip in the united states. It has no terms that are their own parents.

If i nix the final module_invoke_all in taxonomy_term_save, it goes away. If i replace it with a custom taxonomy_term_save containing a call to a custom module_invoke_all that continues over the pathauto update invocation, the problem goes away. I haven't had time to investigate further but there is a problem.

Edit: i'm using 7.x-1.2, not dev.