[Rt-commit] rt branch, 4.4-trunk, updated. rt-4.4.4-504-g3effbaf749
Jim Brandt
jbrandt at bestpractical.com
Wed Jun 2 17:16:19 EDT 2021
The branch, 4.4-trunk has been updated
via 3effbaf7493cce28baf8c3df15b81581e53a7589 (commit)
via 64cd63caf19e2063e3c3fcd1d7119e6e7c91bc76 (commit)
from ea3094cef7ec7639802bbad9f1da9eb1aff54da0 (commit)
Summary of changes:
lib/RT/Interface/Web/QueryBuilder/Tree.pm | 30 ++++++++++++++++++++++++++++++
t/api/tickets.t | 10 ++++++++++
2 files changed, 40 insertions(+)
- Log -----------------------------------------------------------------
commit 64cd63caf19e2063e3c3fcd1d7119e6e7c91bc76
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Jun 2 03:24:13 2021 +0800
On Pg 9 switch key/value pair if value is CF value and key is not
For search criteria with a custom field value as the value
(right hand side), Pg 9 tries to cast *all* ObjectCustomFieldValues
content in the entire query to the type of key instead of just the
ones bound to the specified custom field, e.g.
LastUpdated > CF.{Beta Date}
If there is an ObjectCustomFieldValue row of which content doesn't look
like a datetime (e.g. a URL text for custom field "URL"), the cast to
TIMESTAMP will fail.
This commit avoids this issue by switching key/value pair to
compare using text intead.
diff --git a/lib/RT/Interface/Web/QueryBuilder/Tree.pm b/lib/RT/Interface/Web/QueryBuilder/Tree.pm
index 8327a2abb8..4ddfd7624b 100644
--- a/lib/RT/Interface/Web/QueryBuilder/Tree.pm
+++ b/lib/RT/Interface/Web/QueryBuilder/Tree.pm
@@ -295,6 +295,36 @@ sub ParseSQL {
$callback{'Condition'} = sub {
my ($key, $op, $value, $value_is_quoted) = @_;
+ if ( !$value_is_quoted
+ && $key !~ /(?:CustomField|CF)\./
+ && $value =~ /(?:CustomField|CF)\./
+ && RT->Config->Get('DatabaseType') eq 'Pg' )
+ {
+
+ # E.g. LastUpdated > CF.{Beta Date}
+ #
+ # Pg 9 tries to cast all ObjectCustomFieldValues to datetime,
+ # which could fail since not all custom fields are of DateTime
+ # type. To get around this issue, here we switch the key/value
+ # pair to compare as text instead.
+
+ my ($major_version) = $RT::Handle->dbh->selectrow_array("SHOW server_version") =~ /^(\d+)/;
+ if ( $major_version < 10 ) {
+ my %reverse = (
+ '>' => '<',
+ '>=' => '<=',
+ '<' => '>',
+ '<=' => '>=',
+ '=' => '=',
+ );
+ if ( $reverse{$op} ) {
+ RT->Logger->debug("Switching $key/$value to compare using text");
+ ( $key, $value ) = ( $value, $key );
+ $op = $reverse{$op};
+ }
+ }
+ }
+
my ($main_key, $subkey) = split /[.]/, $key, 2;
unless( $lcfield{ lc $main_key} ) {
diff --git a/t/api/tickets.t b/t/api/tickets.t
index 99648ee68b..ce71e3b6d9 100644
--- a/t/api/tickets.t
+++ b/t/api/tickets.t
@@ -301,6 +301,11 @@ diag "Columns as values in searches";
$count = $tickets->Count();
is( $count, 0, 'Found 0 tickets' );
+ ( $ret, $msg ) = $tickets->FromSQL('CF.{Beta Date} = Due');
+ ok( $ret, 'Ran query with CF.{Beta Date} = Due' );
+ $count = $tickets->Count();
+ is( $count, 0, 'Found 0 tickets' );
+
ok( $ticket->AddCustomFieldValue( Field => $cf_foo, Value => '1900' ) );
for my $operator ( '=', 'LIKE' ) {
( $ret, $msg ) = $tickets->FromSQL("CF.foo $operator 1900");
@@ -315,6 +320,11 @@ diag "Columns as values in searches";
$count = $tickets->Count();
is( $count, 1, 'Found 1 ticket' );
+ ( $ret, $msg ) = $tickets->FromSQL('CF.{Beta Date} = Due');
+ ok( $ret, 'Ran query with CF.{Beta Date} = Due' );
+ $count = $tickets->Count();
+ is( $count, 1, 'Found 1 ticket' );
+
ok( $ticket->AddCustomFieldValue( Field => $cf_beta, Value => $date->ISO( Timezone => 'user' ) ) );
( $ret, $msg ) = $tickets->FromSQL('Due = CF.{Beta Date}.Content');
ok( $ret, 'Ran query with Due = CF.{Beta Date}.Content' );
commit 3effbaf7493cce28baf8c3df15b81581e53a7589
Merge: ea3094cef7 64cd63caf1
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Wed Jun 2 16:38:52 2021 -0400
Merge branch '4.4/columns-as-values-in-ticket-search-pg-9' into 4.4-trunk
-----------------------------------------------------------------------
More information about the rt-commit
mailing list