[OP-19968] Fix 500 when writing end_time on a time entry - #24775
Open
jtauschl wants to merge 2 commits into
Open
[OP-19968] Fix 500 when writing end_time on a time entry#24775jtauschl wants to merge 2 commits into
jtauschl wants to merge 2 commits into
Conversation
end_time is derived (start_time + hours) and has no setter of its own -- the date_time_property declaration had a custom getter but no setter, so Representable fell through to its default send(:end_time=, value) when a client included endTime in a write payload, crashing with NoMethodError since TimeEntry defines no such method. Add an explicit no-op setter, matching how other purely-computed read-only representer properties in this codebase already handle a write attempt.
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
recheck |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the Costs module’s API v3 time entry representer when clients include endTime in write payloads, by explicitly handling the field as unwritable (since end_time is derived from start_time + hours and has no model setter).
Changes:
- Add an explicit no-op setter for the computed
end_timerepresenter property to prevent Representable from calling a non-existentend_time=method. - Add a regression parsing spec ensuring payloads containing
endTimeno longer raise (and should be ignored).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| modules/costs/lib/api/v3/time_entries/time_entry_representer.rb | Adds a no-op setter for computed end_time to avoid NoMethodError on write payloads containing endTime. |
| modules/costs/spec/lib/api/v3/time_entries/time_entry_representer_parsing_spec.rb | Adds a regression spec for parsing write payloads that include endTime. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+126
to
+130
| setter: ->(*) { | ||
| # end_time is derived (start_time + hours), never its own column -- | ||
| # silently accept a write attempt without touching the record, same | ||
| # as any other purely-computed read-only API property. | ||
| }, |
Collapse the setter to a one-line no-op matching this codebase's existing
convention for an ignored representer property (setter: ->(*) {} #
ignored, per query_representer.rb's :hidden property). The regression
spec's respond_to?(:end_time=) assertion was always true/false
independent of whether the payload was actually respected -- TimeEntry
never had that method regardless of the fix. Replaced with an assertion
that a deliberately different endTime value is genuinely ignored,
verified against the value start_time + hours actually derives.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket
https://community.openproject.org/wp/OP-19968
Summary
end_timeis derived (start_time+hours) and has no setter of its own -- thedate_time_propertydeclaration had a custom getter but no setter, so Representable fell through to its defaultsend(:end_time=, value)when a client includedendTimein a write payload, crashing withNoMethodErrorsinceTimeEntrydefines no such method.Change
Add an explicit no-op setter, matching how other purely-computed read-only representer properties in this codebase already handle a write attempt.
Test plan
endTimeis included in a write payloadPOSTwithendTimeset → 500; after the fix → 201, entry created successfully