Index: /trunk/DNSDB.pm
===================================================================
--- /trunk/DNSDB.pm	(revision 185)
+++ /trunk/DNSDB.pm	(revision 186)
@@ -1499,4 +1499,11 @@
   return 0 if $type1 eq 'domain' && $type2 ne 'record';	# domain may not be a parent of anything other than a record
 
+  # ennnhhhh....  if we're passed an id of 0, it will never be found.  usual
+  # case would be the UI creating a new <thing>, and so we don't have an ID for
+  # <thing> to look up yet.  in that case the UI should check the parent as well.
+  # argument for returning 1 is
+  return 0 if $id1 == 0;	# nothing can have a parent id of 0
+  return 1 if $id2 == 0;	# anything could have a child id of 0 (or "unknown")
+
   # group 1 is the ultimate root parent
   return 1 if $type1 eq 'group' && $id1 == 1;
@@ -1510,8 +1517,15 @@
   my $foundparent = 0;
 
+  my $limiter = 0;
   while (1) {
     my $sql = "SELECT $par_col{$type} FROM $par_tbl{$type} WHERE $id_col{$type} = ?";
     my $result = $dbh->selectrow_hashref($sql,
 	undef, ($id) );
+    if (!$result) {
+      $limiter++;
+##fixme:  how often will this happen on a live site?
+      warn "no results looking for $sql with id $id (depth $limiter)\n";
+      last;
+    }
     if ($result && $result->{$par_col{$type}} == $id1) {
       $foundparent = 1;
