[Rt-commit] rt branch, 4.2/txn-cf-warning, created. rt-4.2.13-89-g92ac40f

Shawn Moore shawn at bestpractical.com
Wed Jan 4 17:03:38 EST 2017


The branch, 4.2/txn-cf-warning has been created
        at  92ac40f4b3dcaa61b5fb29268afe9dc325934f59 (commit)

- Log -----------------------------------------------------------------
commit 9484c107232bff5b400ebe44579210197e9b881c
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Jan 4 21:33:27 2017 +0000

    Failing tests for "Couldn't load object RT::Transaction #0"

diff --git a/t/web/ticket_txn_cf.t b/t/web/ticket_txn_cf.t
new file mode 100644
index 0000000..f9db9a1
--- /dev/null
+++ b/t/web/ticket_txn_cf.t
@@ -0,0 +1,124 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+ok $m->login, 'logged in as root';
+my $root = RT::User->new(RT->SystemUser);
+ok( $root->Load('root'), 'load root user' );
+
+my $cf_name = 'test txn cf';
+
+my $cfid;
+diag "Create a CF";
+{
+    $m->follow_link( id => 'admin-custom-fields-create');
+    $m->submit_form(
+        form_name => "ModifyCustomField",
+        fields    => {
+            Name          => $cf_name,
+            TypeComposite => 'Freeform-1',
+            LookupType    => 'RT::Queue-RT::Ticket-RT::Transaction',
+        },
+    );
+    $m->content_contains('Object created', 'created CF sucessfully' );
+    $cfid = $m->form_name('ModifyCustomField')->value('id');
+    ok $cfid, "found id of the CF in the form, it's #$cfid";
+}
+
+diag "apply the CF to General queue";
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+    $m->follow_link( id => 'admin-queues-select');
+    $m->title_is( q/Admin queues/, 'admin-queues screen' );
+    $m->follow_link( text => 'General' );
+    $m->title_is( q/Configuration for queue General/,
+        'admin-queue: general' );
+    $m->follow_link( id => 'page-custom-fields-transactions' );
+    $m->title_is( q/Custom Fields for queue General/,
+        'admin-queue: general cfid' );
+
+    $m->form_name('EditCustomFields');
+    $m->tick( "AddCustomField" => $cfid );
+    $m->click('UpdateCFs');
+
+    $m->content_contains('Object created', 'TCF added to the queue' );
+}
+
+my ( $ticket, $id );
+diag 'submit value on ticket create page';
+{
+
+    $m->submit_form(
+        form_name => "CreateTicketInQueue",
+        fields    => { Queue => 'General' },
+    );
+    $m->content_contains($cf_name, 'has cf field' );
+
+    $m->submit_form(
+        form_name => "TicketCreate",
+        fields    => {
+            Subject                                            => 'test 2017-01-04',
+            Content                                            => 'test',
+            "Object-RT::Transaction--CustomField-$cfid-Values" => 'hello from create',
+        },
+    );
+    ok( ($id) = $m->content =~ /Ticket (\d+) created/, "created ticket $id" );
+
+    $ticket = RT::Ticket->new(RT->SystemUser);
+    $ticket->Load($id);
+    is( $ticket->Transactions->First->CustomFieldValues($cfid)->First->Content,
+        'hello from create', 'txn cf value in db' );
+
+    $m->content_contains($cf_name, 'has txn cf name on the page' );
+    $m->content_contains('hello from create',
+        'has txn cf value on the page' );
+}
+
+diag 'submit value on ticket update page';
+{
+    $m->follow_link_ok( { text => 'Reply' }, "reply to the ticket" );
+
+    $m->content_contains($cf_name, 'has cf field' );
+
+    $m->form_name('TicketUpdate');
+    $m->field(UpdateContent => 'test 2');
+    $m->field("Object-RT::Transaction--CustomField-$cfid-Values" => 'hello from update');
+    $m->click('SubmitTicket');
+
+    $m->content_contains('Correspondence added');
+
+    my $txns = $ticket->Transactions;
+    $txns->Limit(FIELD => 'Type', VALUE => 'Correspond');
+    is( $txns->Last->CustomFieldValues($cfid)->First->Content,
+        'hello from update', 'txn cf value in db' );
+
+    $m->content_contains($cf_name, 'has txn cf name on the page' );
+    $m->content_contains('hello from update',
+        'has txn cf value on the page' );
+}
+
+diag 'submit no value on ticket update page';
+{
+    $m->follow_link_ok( { text => 'Reply' }, "reply to the ticket" );
+
+    $m->content_contains($cf_name, 'has cf field' );
+
+    $m->form_name('TicketUpdate');
+    $m->field(UpdateContent => 'test 2');
+    $m->click('SubmitTicket');
+
+    $m->content_contains('Correspondence added');
+
+    my $txns = $ticket->Transactions;
+    $txns->Limit(FIELD => 'Type', VALUE => 'Correspond');
+    is( $txns->Last->CustomFieldValues($cfid)->Count,
+        0, 'no txn cf value in db' );
+}
+
+undef $m;
+done_testing;
+

commit 92ac40f4b3dcaa61b5fb29268afe9dc325934f59
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Jan 4 21:40:02 2017 +0000

    Avoid "Couldn't load object RT::Transaction #0" warning
    
    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

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index cbf10d2..513bf32 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -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");

-----------------------------------------------------------------------


More information about the rt-commit mailing list