# Bug OP-19968 - Writing end_time on a time entry crashes with NoMethodError (500)

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

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module | Modules and project features / Time tracking, API |
| Target versions | 17.9.0 |
| Observed in versions |  |
| Sprint |  |
| 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 |  |
| Product manager |  |
| Developers | Oliver Günther |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

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

## Costs

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

## Description

### Before filing a report

Confirmed reproducible on the latest available patch release of the 17.7 minor line (17.7.1, the latest at the time of testing) via direct REST API calls against a real instance. Searched community.openproject.org for existing reports (by "time_entries end_time NoMethodError", "time entry end_time writable", "TimeEntry end_time setter") — found no existing report covering this. A minimal, verified fix is proposed below, also submitted as a pull request: https://github.com/opf/openproject/pull/24775

### Steps to reproduce

1. Enable Administration → Time and costs → "Allow start and finish times" (the `allow_tracking_start_and_end_times` setting, disabled by default -- the `startTime`/`endTime` properties are entirely hidden from the schema/representer while it's off).
2. Login as a user with permissions to log time on a work package.
3. Send `POST /api/v3/time_entries` with a valid `hours`, `spentOn`, `startTime`, `_links.project`, `_links.workPackage`, AND an `endTime` field set, e.g.:
   ```json
   {
     "comment": {"raw": "test"},
     "hours": "PT1H",
     "spentOn": "2026-08-13",
     "startTime": "2026-08-13T09:00:00Z",
     "endTime": "2026-08-13T10:00:00Z",
     "_links": {
       "project": {"href": "/api/v3/projects/{id}"},
       "workPackage": {"href": "/api/v3/work_packages/{id}"}
     }
   }
   ```

### What is the buggy behavior?

The request returns **HTTP 500** instead of either ignoring the read-only field or rejecting it cleanly:
```json
{"_type":"Error","errorIdentifier":"urn:openproject-org:api:v3:errors:InternalServerError","message":"An internal error has occurred. undefined method 'end_time=' for an instance of #<Class:...>"}
```

`end_time` is schema-marked `writable: false` (`modules/costs/lib/api/v3/time_entries/schemas/time_entry_schema_representer.rb`), and is documented as purely DERIVED -- `TimeEntry` (`modules/costs/app/models/time_entry.rb`) computes `end_timestamp` from `start_timestamp + hours` and has no `end_time` database column or `end_time=` method at all.

Root cause: the representer's `date_time_property :end_time` (`modules/costs/lib/api/v3/time_entries/time_entry_representer.rb`) declares a custom `getter:` but no `setter:`. When a client sends `endTime` in the write payload anyway, Representable falls through to its own default setter behavior, which calls `send(:"end_time=", value)` on the model -- and since no such method exists, this raises a raw `NoMethodError` that propagates uncaught to the API caller.

### What is the expected behavior?

Since `end_time` is documented as read-only and purely derived, a client attempting to set it should either have the value silently ignored (consistent with existing representer properties elsewhere in this codebase that intentionally ignore writes via a no-op setter) or receive a clean `422` explaining the field is not writable -- but never crash the request with an opaque 500.

### Logs

```
HTTP/1.1 500 Internal Server Error
content-type: application/hal+json; charset=utf-8
{"_type":"Error","errorIdentifier":"urn:openproject-org:api:v3:errors:InternalServerError","message":"An internal error has occurred. undefined method 'end_time=' for an instance of #<Class:0x0000fcd27aa23178>"}
```

### Screenshots and other files

None — this is a pure backend/API bug with no UI reproduction path tested; the REST API reproduction above is sufficient to demonstrate it independent of any client.

### Environment information

**OpenProject installation type**

* Docker All-in-one container (official `openproject/openproject` image: `17.7.1`)

**OpenProject version**

Reproduced on `17.7.1` (the latest release in the 17.7 line at the time of testing). Confirmed present unchanged in source on the `dev` branch (checked against the full source checkout).

**Browser**

Not applicable — reproduced via direct REST API calls, no browser involved.

**Operating System**

Not applicable — server-side bug, reproduced against a Linux-based Docker container; the client OS is irrelevant to the reproduction.

**Language**

Not applicable — no UI/browser interaction involved in the reproduction.
