[Rt-commit] rt branch, 4.4/columns-as-values-in-ticket-search-pg-9, created. rt-4.4.4-503-g16a065e03b

? sunnavy sunnavy at bestpractical.com
Tue Jun 1 17:23:48 EDT 2021


The branch, 4.4/columns-as-values-in-ticket-search-pg-9 has been created
        at  16a065e03b0166bf025c11f0056155ecd91e3de1 (commit)

- Log -----------------------------------------------------------------
commit 16a065e03b0166bf025c11f0056155ecd91e3de1
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jun 2 03:24:13 2021 +0800

    Switch key/value pair if value is custom field value and key is not for Pg 9
    
    For criteria that custom field value as the value, Pg 9 tries to cast
    *all* ObjectCustomFieldValues content 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 will
    fail.
    
    This commit gets around 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} ) {

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


More information about the rt-commit mailing list