Custom module with custom node type, error Trying to get property of non-object en comment_node_type_delete() I'm quite new with Drupal 7 development, after researching and following some tutorials I was able to create my custom module that defines a new node type with some fields, but now I have a problem when I uninstall it, the hook_uninstall runs almost fine(the node type, the contents from my custom node, and the node fields), except that display this error after the uninstall:


  Notice: Trying to get property of non-object en
  comment_node_type_delete() (línea 344 de
  /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice:
  Trying to get property of non-object en comment_node_type_delete()
  (línea 355 de
  /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice:
  Trying to get property of non-object en comment_node_type_delete()
  (línea 355 de
  /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice:
  Trying to get property of non-object en comment_node_type_delete()
  (línea 355 de
  /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice:
  Trying to get property of non-object en comment_node_type_delete()
  (línea 355 de
  /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice:
  Trying to get property of non-object en comment_node_type_delete()
  (línea 355 de
  /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice:
  Trying to get property of non-object en comment_node_type_delete()
  (línea 355 de
  /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice:
  Trying to get property of non-object en comment_node_type_delete()
  (línea 355 de
  /opt/lampp/htdocs/drupal/modules/comment/comment.module).


This is from mymodule.install:

function mynode_uninstall() {

    $ournewtype = 'mynode';
    $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
    $result = db_query($sql, array(':type' =&gt; $ournewtype));
    $nodeids = array();
    foreach ($result as $row) {
        $nodeids[] = $row-&gt;nid;
    }
    node_delete_multiple($nodeids);
    node_type_delete($ournewtype);
    field_purge_batch(500);
    drupal_flush_all_caches();
}
I believe the problem is that it's expecting an object, and you are passing a string. Try changing this:

node_type_delete($ournewtype);


To this:

$node_type = node_type_load($ournewtype);
node_type_delete($node_type);


One other thing, instead of this:

$result = db_query($sql, array(':type' =&gt; $ournewtype));
$nodeids = array();
foreach ($result as $row) {
    $nodeids[] = $row-&gt;nid;
}


You can simplify it by using this:

$nodeids = db_query($sql, array(':type' =&gt; $ournewtype))-&gt;fetchCol();