path_set_alias() generates the wrong alias, and creates a 301 redirect to the desired alias's path I'm creating a webform when organic groups are created and I'm trying to set an alias for it with hook_nodeapi(). It successfully creates the alias when the insert operation for the group is called after the webform has been created and associated to the group, but if you edit and update the group it does not update the alias with the code I have written. and a SQL error is displayed.

Here is the code that is called by hook_nodeapi() on insert and update operations:

// Webform
$nid = $node-&gt;field_webform_id[0]['value'];
$webform = db_fetch_object(db_query("SELECT count(src) as total FROM {url_alias} WHERE src = 'node/%d'", $nid));
if ($webform-&gt;total &gt; 0) {
  db_query("DELETE FROM {url_alias} WHERE src LIKE 'node/%d'", $nid);
}
path_set_alias('node/'.$nid, 'local/'.$state.'/'.$county.'/submit-tip');


I'm getting the webform node ID from a CCK field on the group, checking if there are aliases set already for that node, and deleting them from the url_alias table. Then I'm using path_set_alias to recreate an alias (in this case it is the same as before).

The error message displayed when updating a group:


  user warning: Duplicate entry 'local/pa/adams/submit-tip-' for key
  'source_language' query: INSERT INTO path_redirect (source, redirect,
  query, fragment, language, type, last_used) VALUES
  ('local/pa/adams/submit-tip', 'node/209', '', '', '', 301, 1311098626)
  in
  /var/aegir/platforms/crimewatchpa-dev-v2011-07-12-15-42/includes/common.inc
  on line 3538.


Instead of creating local/pa/adams/submit-tip as an alias to node/209, it creates an alias submit-tip-0 (submit-tip already exists on another node). A 301 redirect is also created with the path: local/pa/adams/submit-tip to node/209.
The trick was to set $node-&gt;pathauto_perform_alias = FALSE; before calling node_save.  Then my manual aliasing was allowed to take effect.

I still haven't figured out how to prevent the 301 redirect.  It only produces a warning now, and the alias stays the way I want.