# Bug OP-16467 - API: project/{id}/work_packages?select=total fails when there are no work packages

Project: OpenProject
Status: closed
URL: https://community.openproject.org/work_packages/OP-16467

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module | API |
| Target versions | 16.4.0 |
| Observed in versions |  |
| Sprint | 16.4.0 |
| Backlog bucket |  |
| Bug found in version (deprecated) |  |
| Found in mobile app version |  |
| Follow-up feedback e-mail |  |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable | Eric Schubert |
| Product manager |  |
| Developers | Eric Schubert |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

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

## Costs

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

## Description

### Before filing a report

*Before you file a report, please ensure you are running the latest version of OpenProject and*   
*have searched for similar bug reports.*

### Steps to reproduce

*Please write down the steps to reproduce. Try to write down all necessary preconditions (what permissions do you have, are other users involved?). Example:*

1.  Log into OpenProject or auth through the API

2.  GET request to `project/{id}/work_packages?select=total` endpoint for a project with 0 work packages (filter dependent - if the filter responses with an empty set, this will reproduce)

### What is the buggy behavior?

*Please describe the bug in as much detail as possible. Example:*

  - `?select=total` on empty set will cause the following error / server-side failure:

> {  
>  "\_type": "Error",  
>  "errorIdentifier": "urn:openproject-org:api:v3:errors:InternalServerError",  
>  "message": "An internal error has occurred.undefined method \`\[\]' for nil"  
> }

### What is the expected behavior?

*Describe how the application should behave like. Example:*

1.  No failure\! It should return `{ "total" : 0 }`

### Environment information

*Please check and fill out the following details to help us identify in what versions and distributions of OpenProject the error occurs*

**OpenProject installation type**

  - Hosted cloud edition

**Browser**

- [x] Chrome
- [x] Firefox
- [ ] Safari
- [ ] Mobile Safari
- [ ] Other (please specify)

**Operating System**

- [x] Windows
- [ ] Mac OS X
- [ ] Mobile iOS
- [ ] Mobile Android
- [ ] Linux (please specify distro)
- [ ] Chrome OS
- [ ] Other (please specify)

**Language**

*English*

### Hints for QA

  - the endpoint to test this is `GET /api/v3/projects/:id/work_packages?select=total`

  - it can be executed directly in the browser with the id of any project, that has or has no work packages
