6.0.0-git
2018-12-16

[#14819] Rdo throws inappropriate exception
Summary Rdo throws inappropriate exception
Queue Horde Framework Packages
Type Bug
State Unconfirmed
Priority 1. Low
Owners
Requester birnbacs (at) gmail (dot) com
Created 2018-05-27 (203 days ago)
Due
Updated 2018-05-27 (203 days ago)
Assigned
Resolved
Milestone
Patch Yes

History
2018-05-27 13:29:18 birnbacs (at) gmail (dot) com Comment #2 Reply to this comment
The referenced ticket is 14818
2018-05-27 12:33:54 birnbacs (at) gmail (dot) com Comment #1
Type ⇒ Bug
State ⇒ Unconfirmed
Priority ⇒ 1. Low
Summary ⇒ Rdo throws inappropriate exception
Queue ⇒ Horde Framework Packages
Milestone ⇒
Patch ⇒ Yes
Reply to this comment
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] = 
$m->findOne($this->{$rel['foreignKey']});
                 $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;
             }
             break;


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.

Saved Queries