Repository navigation
Conversation
TimeEntryCreateSchema checked cross-field rules in field-level @validates hooks that read kwargs["data"]. Marshmallow 4 passes only data_key to those hooks, so the other fields were never visible: - POST /api/v1/time-entries rejected every task_id, even with project_id; - "project_id": null with a client_id (and the reverse) was rejected; - end_time <= start_time was never caught by the schema. Move the rules into one @validates_schema hook, as in TimerStartSchema. Messages and field keys are unchanged. A naive start with an aware end is left to the service, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEehhsUMojSDD4gn58PMHK
This branch has not been deployed
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.
Description
POST /api/v1/time-entriesrejects everytask_id, even whenproject_idis sent.Steps to reproduce:
POST /api/v1/time-entrieswith{"project_id": 1, "task_id": 2, "start_time": "2026-11-03T09:00:00", "end_time": "2026-11-03T10:30:00"}(task 2 belongs to project 1).400 {"task_id": ["task_id can only be set when project_id is provided"]}.Expected:
201withtask_idset. Today an API client has to create the entry without a task and thenPATCHthe task in.Cause:
TimeEntryCreateSchemachecks its cross-field rules in field-level@validateshooks that readkwargs["data"]. Marshmallow 4 (4.4.0 inrequirements.txt) passes onlydata_keyto those hooks, so the other fields are never visible. Besidestask_id, this means:"project_id": nulltogether with aclient_id(and"client_id": nullwith aproject_id) is rejected;end_time <= start_timeis never caught by the schema (the service still catches it).Fix: the same rules in one
@validates_schemahook, the wayTimerStartSchemaalready does it. Error messages and field keys are unchanged. If one time is naive and the other aware, the schema skips the comparison and leaves it to the service, as before.Environment: TimeTracker 5.21.0 (Docker), marshmallow 4.4.0, PostgreSQL 16.
Type of change
Checklist
pytest).Tests:
tests/test_routes/test_api_v1_time_entry_create_validation.py, 14 cases over the API and the schema. 10 of them fail without the fix. With the fix, they pass together withtests/test_api_v1.pyandtests/test_routes/test_api_v1_time_entries_refactored.py(62 passed). We have run this fix in production on our fork since 5.21.0.Related issues
None filed; the PR describes the bug.