Repository navigation
Check a task's change request visibility on the copy the write route loaded - #38001
Conversation
…loaded The comment and PATCH routes read the task from the database, then checked whether the caller may read its change request by loading the task again through the entity cache. That second read cached the task as it was before the write, and the comment write does not evict it, so with the Redis cache a later read returned the task without the new comment (TaskCommentsIT in the cache lane). The write routes now pass the task they already loaded, and the resolve check uses that copy. Reads of a task's versions still load it by id.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
Code Review ✅ Approved 🔴 High riskWrite routes now evaluate change-request visibility against the loaded task, changing authorization decisions; mismatched task state could expose proposed values. Write routes for task comments and PATCH now pass the already-loaded task into the change request visibility check, instead of reloading it through the entity cache, so the Redis-cached read no longer returns a stale task missing new comments. No issues found. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
| || seesAll(caller, entity) | ||
| || mayResolveTask(authorizer, securityContext, task.getId()); | ||
| || mayResolve( | ||
| (TaskRepository) Entity.getEntityRepository(Entity.TASK), |
There was a problem hiding this comment.
Repository lookup breaks injection rule.
mayRead now calls Entity.getEntityRepository directly. The Java guide requires constructor-injected repositories and says not to look up static singletons inside business methods. Supply the repository through an injected dependency while keeping the already-loaded task; this also lets tests supply a repository without changing global state.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Describe your changes:
Fixes open-metadata/openmetadata-collate#8655
Follow-up to #37997.
TaskCommentsIT.test_getTaskWithComments_successfails in the PostgreSQL + Elasticsearch + Redis lane onmainsince #37997 (run 44142706227): two comments are added, and the task read back shows one.The comment and
PATCHroutes read the task from the database (repository.get, not cached), then checked whether the caller may read the task's change request withChangeRequestVisibility.requireTaskVisible(id), which loaded the task again through the entity cache. That read cached the task as it was before the write, and the comment write (TaskRepository.addComment→storeEntity) does not evict it, so with the Redis cache the next read returned the task without the new comment. The stored task was correct.The write routes (add, edit and delete comment,
PATCH) now pass the task they already loaded, and the resolve check uses that copy instead of reloading it. The versions routes still load the task by id; they only read.Type of change:
Tests:
TaskCommentsITwith-Pcache-tests(PostgreSQL + Elasticsearch + Redis), locally:main(65a6afb): 3 runs,test_getTaskWithComments_successfailed in all 3 (expected: <2> but was: <1>).WorkflowDefinitionResourceIT.test_taskReadsShowAPendingValueOnlyToWhoMaySeeItsChangeRequest(the 403 for viewers outside the change request rule, values for the requester and reviewer):-Pcache-tests1 run, 0 failures; MySQL 1 run, 0 failures.Checklist:
TaskCommentsITin the cache lane, which fails without this change.🤖 Generated with Claude Code
The repository dependency must be supplied as required before merging; no new behavior bugs were found.
Findings
Summary
Task writes now check change-request access using the task already loaded from the database, avoiding an extra cache read before saving.
Reviews (5) · Last reviewed commit: "Check a task's change request visibility..." · Reviewed by Greptile