Hi,

if the the CCK field name is too long, the total fields are not displayed. In the views_calc_table_total function the $totals object looks like this:

stdClass Object
(
    [node_data_field_saco_title_field_saco_title_value] => 
    [node_data_field_saco_title_field_saco_set_node_nid] => 
    [node_data_field_common_list_price_field_common_list_price_va] => 
    [SUM__node_data_field_common_list_price_field_common_list_pri] => 384767.00
    [node_data_field_saco_title_field_saco_quantity_value] => 
    [SUM__node_data_field_saco_title_field_saco_quantity_value] => 70
)

The totals are present, but the lookup variable $ext_alias is set to

SUM__node_data_field_common_list_price_field_common_list_price_va

which fails to retreive the value from $totals.

Why are the variable names truncated to 61 characters?

/Kevin

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kevin.mcnamee@mailbox.org’s picture

Workaround for getting the totals displayed.

marcp’s picture

Status: Active » Needs work

Just ran into this and the patch appears to fix the bug, but I think it would be more accurate to fix the problem in the $totals array. I haven't delved in enough to see where things are getting truncated in there.

If there are two long field names that just differ past the 60th character, they'll get confused with this fix, right?

kevin.mcnamee@mailbox.org’s picture

Right. Note that I called the patch a "workaround"; it is not intended as a proper fix.

pvanerk’s picture

Thanks for your workaround. It works for me.

kevin.mcnamee@mailbox.org’s picture

The problem seems to be related to how field aliases are created in the core Views module. The following line of code from views/plugins/views_plugin_query_default.inc line 691 are interesting

    // PostgreSQL truncates aliases to 63 characters: http://drupal.org/node/571548
 
    // We limit the length of the original alias up to 60 characters
    // to get a unique alias later if its have duplicates
    $alias = substr($alias, 0, 60);

If I comment out this line and remove the workaround mentioned above, then the totals are displayed. Unfortunately, I can't make any sense of explanation in the code.

In general, this seems like a rather hasty patch that was created to solve a specific problem for Postgres. It does not take into account the resulting namespace collisions (i.e. truncating can result in duplicate field aliases) that can occur. This is evidenced by the still ongoing discussion on the same issue #571548: Identifiers longer than 63 characters are truncated, causing Views to break on Postgres. Several alternate patch solutions have been proposed, including one using 'MD5'ed aliases which looks promising.

/Kevin

Anonymous’s picture

Or if you're not using PostgreSQL, you can do as I did & undo the hasty change in Views that's causing this.

In views/plugins/views_plugin_query_default.inc:

//    $alias = strtolower(substr($alias, 0, 60));
    $alias = strtolower($alias);
KarenS’s picture

Issue summary: View changes

Reported and fixed in another issue.

KarenS’s picture

Status: Needs work » Closed (duplicate)