Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent error about undefined value in next_previous route #4574

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/OpenQA/WebAPI/Controller/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,15 @@ sub infopanel {
$self->render('test/infopanel');
}

sub get_current_job ($self, $with_assets = 0) {
sub _get_current_job ($self, $with_assets = 0) {
return $self->reply->not_found unless defined $self->param('testid');

my $job = $self->schema->resultset("Jobs")
->find($self->param('testid'), {$with_assets ? (prefetch => qw(jobs_assets)) : ()});
return $job;
}

sub show ($self) { $self->_show($self->get_current_job(1)) }
sub show ($self) { $self->_show($self->_get_current_job(1)) }

sub _show {
my ($self, $job) = @_;
Expand All @@ -428,7 +428,7 @@ sub _show {
}

sub job_next_previous_ajax ($self) {
my $main_job = $self->get_current_job;
return $self->reply->not_found unless my $main_job = $self->_get_current_job;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind extending our unit tests to cover this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this not necessary, it's just basic in-line safety checks which doesn't even touch coverage. Please also see #4575 where I try to make the overall code simpler with exception handling so that we don't need these checks at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow. I'm asking if we can have a regression test since this issue was only seen in production.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think a test would be nice

my $main_jobid = $main_job->id;
my $p_limit = $self->param('previous_limit') // 400;
my $n_limit = $self->param('next_limit') // 100;
Expand Down Expand Up @@ -892,7 +892,7 @@ sub _add_job ($dependency_data, $job, $as_child_of, $preferred_depth) {
sub dependencies ($self) {

# build dependency graph starting from the current job
my $job = $self->get_current_job or return $self->reply->not_found;
my $job = $self->_get_current_job or return $self->reply->not_found;
my (@nodes, @edges, %cluster);
my %data = (visited => {}, nodes => \@nodes, edges => \@edges, cluster => \%cluster, cluster_by_job => {});
_add_job(\%data, $job, 0, $job->ancestors);
Expand All @@ -901,7 +901,7 @@ sub dependencies ($self) {

sub investigate {
my ($self) = @_;
return $self->reply->not_found unless my $job = $self->get_current_job;
return $self->reply->not_found unless my $job = $self->_get_current_job;
my $investigation = $job->investigate;
$self->render(json => $investigation);
}
Expand Down