# Bug COMMS-963 - Versions PG::UndefinedTable during a query 

Project: Stream Communicator
Status: closed
URL: https://community.openproject.org/work_packages/COMMS-963

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module |  |
| Target versions | 17.8.1 |
| Observed in versions | 17.7.0 |
| Sprint | Sprint 14 |
| Backlog bucket |  |
| Bug found in version (deprecated) | 17.7.x |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Developers | Kabiru Mwenja |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

### Steps to reproduce

1.  Log in as a user with &quot;View work packages&quot; and &quot;View sprints&quot; in a project with the Backlogs module enabled and at least one backlog bucket.
    
2.  Open a work package table.
    
3.  Group by &quot;Backlog bucket&quot; and sort by &quot;Version&quot; (on 17.8/dev: sort by &quot;Category&quot; instead).
    
4.  Reload the view.
    

### What is the buggy behavior?

The view fails to load; `GET /api/v3/queries/:id` returns a 500:

```text
PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "versions"
LINE 2: ...ckages.id )) ORDER BY visible_buckets.name, LOWER(versions.n...
```

The work package list, group counts and sums of such a query all fail. Cause: the backlog bucket join (also sprint, project phase) makes Rails skip eager loading of the sort columns&#x27; associations, so the ORDER BY references a table that is never joined.

### What is the expected behavior?

The table loads grouped by backlog bucket and sorted by the selected column, with counts and sums.

### Logs

Backtrace: `Query::Results::Sums#sums_select` (sums.rb:82) via `API::V3::WorkPackageCollectionFromQueryService#generate_total_sums`.

Appsignal trace: [https://appsignal.com/openproject-gmbh/sites/674718f1d2a5e4a7cb8b2298/exceptions/incidents/1047/traces/last](https://appsignal.com/openproject-gmbh/sites/674718f1d2a5e4a7cb8b2298/exceptions/incidents/1047/traces/last)

### Environment information

**OpenProject installation type**

*   Hosted cloud edition
    

**OpenProject version**

*   17.7.3; still reproducible on `release/17.8` and `dev` with a Category sort
