Bugzilla – Attachment 117376 Details for
Bug 27806
Exceptions thrown during a call to ->render are not caught and passed to ->unhandled_exception
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27806: (follow-up) Add Koha::Exception for bad queries
Bug-27806-follow-up-Add-KohaException-for-bad-quer.patch (text/plain), 2.82 KB, created by
Martin Renvoize (ashimema)
on 2021-02-26 13:29:10 UTC
(
hide
)
Description:
Bug 27806: (follow-up) Add Koha::Exception for bad queries
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-02-26 13:29:10 UTC
Size:
2.82 KB
patch
obsolete
>From 1a380d05a267e54a124af4d4da1b9b1eaafec50c Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 25 Feb 2021 15:21:17 +0000 >Subject: [PATCH] Bug 27806: (follow-up) Add Koha::Exception for bad queries > >This patch adds a PropertyNotFound exception tothe 'as_list' method to >catch DBIx::Class excpetions caused by passing bad column names into a >query. >--- > Koha/Exceptions/Object.pm | 4 ++++ > Koha/Objects.pm | 29 +++++++++++++++++++++++++++-- > 2 files changed, 31 insertions(+), 2 deletions(-) > >diff --git a/Koha/Exceptions/Object.pm b/Koha/Exceptions/Object.pm >index 688a97cd5a..0e0742e655 100644 >--- a/Koha/Exceptions/Object.pm >+++ b/Koha/Exceptions/Object.pm >@@ -40,6 +40,7 @@ use Exception::Class ( > 'Koha::Exceptions::Object::PropertyNotFound' => { > isa => 'Koha::Exceptions::Object', > description => "Invalid property", >+ fields => ['property', 'clause'], > }, > 'Koha::Exceptions::Object::ReadOnlyProperty' => { > isa => 'Koha::Exceptions::Object', >@@ -84,6 +85,9 @@ sub full_message { > elsif ( $self->isa('Koha::Exceptions::Object::NotInstantiated') ) { > $msg = sprintf("Tried to access the '%s' method, but %s is not instantiated", $self->method, $self->class ); > } >+ elsif ( $self->isa('Koha::Exceptions::Object::PropertyNotFound') ) { >+ $msg = sprintf("Invalid property '%s' in '%s' clause", $self->property, $self->clause ); >+ } > } > > return $msg; >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index 2f16b35888..06f3a18f64 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -22,6 +22,7 @@ use Modern::Perl; > use Carp; > use List::MoreUtils qw( none ); > use Class::Inspector; >+use Try::Tiny; > > use Koha::Database; > use Koha::Exceptions::Object; >@@ -409,9 +410,33 @@ Returns an arrayref of the objects in this set. > =cut > > sub as_list { >- my ( $self ) = @_; >+ my ($self) = @_; > >- my @dbic_rows = $self->_resultset()->all(); >+ my @dbic_rows = try { >+ $self->_resultset()->all(); >+ } >+ catch { >+ if ( ref($_) eq 'DBIx::Class::Exception' ) { >+ #warn $_->{msg}; >+ if ( $_->{msg} =~ >+ /Unknown column '(?<column>.*?)' in 'where clause'/ ) >+ { >+ Koha::Exceptions::Object::PropertyNotFound->throw( >+ property => $+{column}, >+ clause => 'where' >+ ); >+ } >+ elsif ( $_->{msg} =~ >+ /Unknown column '(?<column>.*?)' in 'order clause'/ ) >+ { >+ Koha::Exceptions::Object::PropertyNotFound->throw( >+ property => $+{column}, >+ clause => 'order' >+ ); >+ } >+ } >+ $_->rethrow(); >+ }; > > my @objects = $self->_wrap(@dbic_rows); > >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27806
: 117376 |
117377