[#14819] Rdo throws inappropriate exception
Summary Rdo throws inappropriate exception
Queue Horde Framework Packages
Type Bug
State Unconfirmed
Priority 1. Low
Requester birnbacs@gmail.com
Created 2018-05-27 (420 days ago)
Updated 2018-05-27 (420 days ago)
Patch Yes

birnbacs@gmail.com 2018-05-27 12:33:54
This is in reference to /usr/local/share/pear/Horde/Rdo/Base.php.

Among the problems I encounterd using a ONE_TO_ONE lazy relationship 
is one where "a serious error" problem occurs when the target of the 
relationship does not exist.

IOW I have an Rdo object A with a ONE_TO_ONE lazy relationship to Rdo 
object B. If there is no object B an error is thrown upon any attempt 
to access B (like in (if empty(B) { do_somthing }). This does not seem 
to happen with any of the other relationships and it also appears to 
be out of place.

I commented out line 132 where the Exception is thrown:

         case Horde_Rdo::ONE_TO_ONE:
         case Horde_Rdo::MANY_TO_ONE:
             if (isset($rel['query'])) {
                 $query = $this->_fillPlaceholders($rel['query']);
                 $this->_fields[$field] = $m->findOne($query);
             } elseif (!empty($this->{$rel['foreignKey']})) {
                 //$this->_fields[$field] = 
                 $this->_fields[$field] = 
$m->findOne(array($rel['foreignKey'] => $this->{$rel['foreignKey']})); 
// amended SB 2018-05-23 to fix ONE_TO_ONE access problem
                 if (empty($this->_fields[$field])) {
                     //throw new Horde_Rdo_Exception('The referenced 
object with key ' . $this->{$rel['foreignKey']} . ' does not exist. 
Your data is inconsistent');
             } else {
                 $this->_fields[$field] = null;

Please note that the above code comprises another fix I introduced 
recently (bug report pending).

I cannot see a situation where an empty result to the findOne() should 
cause an exception - but am of course eager to learn the better.

birnbacs@gmail.com 2018-05-27 13:29:18
The referenced ticket is 14818