Skip to content

Commit

Permalink
Avoid "Couldn't load object RT::Transaction #0" warning
Browse files Browse the repository at this point in the history
This can occur when a user submits the ticket reply page with a
transaction custom field.

The field name for that transaction custom field looks like:

    Object-RT::Transaction--CustomField-1-Value

Recall that ordinarily, such custom field input names have the record id
that we're modifying. But in this case, since we're creating a record
(of class RT::Transaction), we don't have an id yet, hence the double
dash between the class name and "CustomField". For most record types,
this ends up working out because when we call
ProcessObjectCustomFieldUpdates, RT will have already created the
primary record and provided it as the "Object" argument, which is used
for such "orphan" form fields. This is the codepath that, for example,
specifying custom fields during creation of a group in the admin UI
uses.

In the case of ticket transactions, the ticket update logic in
/Ticket/Display.html does not provide such an Object argument (and is
not readily amenable to doing so, as the transaction is created and
falls out of scope within ProcessUpdateMessage), and so
ProcessObjectCustomFieldUpdates is left with both an orphan
"Object-RT::Transaction--CustomField-1-Value" field name as well as no
loaded RT::Transaction Object to use instead. This ends up causing no
transaction object to be present, leading to the warning "Couldn't load
object RT::Transaction #0".

Incidentally, ticket transaction custom fields are added in a separate
codepath: RT::Interface::Web ProcessUpdateMessage's calls to
$Object->UpdateCustomFields.

In cases where we have an orphan field name ($id false), and no loaded
Object was provided (false $Object->id), we have nothing to load, and so
the "Couldn't load object $class #0" warning is inappropriate.

See previous commit for tests (t/web/ticket_txn_cf.t) which tickle the
warning.

Fixes: I#31548
  • Loading branch information
sartak committed Jan 4, 2017
1 parent 9484c10 commit 92ac40f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/RT/Interface/Web.pm
Expand Up @@ -3067,6 +3067,9 @@ sub ProcessObjectCustomFieldUpdates {
$Object = $class->new( $session{'CurrentUser'} )
unless $Object && ref $Object eq $class;

# skip if we have no object to update
next unless $id || $Object->id;

$Object->Load($id) unless ( $Object->id || 0 ) == $id;
unless ( $Object->id ) {
$RT::Logger->warning("Couldn't load object $class #$id");
Expand Down

0 comments on commit 92ac40f

Please sign in to comment.