Skip to content

fix: migrate KnowledgePage approval task from FeedRepository to TaskRepository - #31972

Closed
zhang-arvin wants to merge 1 commit into
open-metadata:mainfrom
zhang-arvin:fix/issue-31687-knowledgepage-approval
Closed

zhang-arvin wants to merge 1 commit into
open-metadata:mainfrom
zhang-arvin:fix/issue-31687-knowledgepage-approval

Conversation

@zhang-arvin

@zhang-arvin zhang-arvin commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #31687

Migrate updateTaskWithNewReviewers() and closeApprovalTask() from the legacy FeedRepository path to the Task entity API. Also add updateReviewers() override to detect reviewer changes and reassign approval tasks.

Greptile Summary

The PR migrates KnowledgePage approval-task closure and reviewer reassignment from the legacy feed-thread repository to TaskRepository.

  • Adds reviewer-change handling that updates approval-task assignees.
  • Closes approval tasks through the Task entity API using the page FQN.
  • Removes legacy feed patching, closure, and WebSocket-notification code.

Confidence Score: 5/5

The PR appears safe to merge based on the currently established behavior.

No blocking failure remains.

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java Migrates approval-task reassignment and closure to TaskRepository; no new eligible follow-up finding was established.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[KnowledgePage update] --> B{Change type}
  B -->|Reviewers changed| C[Update reviewer relationships]
  C --> D[TaskRepository updates approval assignees]
  B -->|Approved, rejected, or draft| E[TaskRepository finds open Approval task by page FQN]
  E --> F[Close approval task]
Loading

Reviews (2): Last reviewed commit: "fix: migrate KnowledgePage approval task..." | Re-trigger Greptile

Context used:

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This 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 skip-pr-checks label.

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@zhang-arvin
zhang-arvin force-pushed the fix/issue-31687-knowledgepage-approval branch from c7a0954 to 976520a Compare August 25, 2026 01:59
@zhang-arvin
zhang-arvin requested a review from a team as a code owner August 25, 2026 01:59
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@zhang-arvin
zhang-arvin force-pushed the fix/issue-31687-knowledgepage-approval branch from 976520a to 87b3556 Compare August 25, 2026 13:52
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@gitar-bot

gitar-bot Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 4 closed / 5 findings

Migrates KnowledgePage approval tasks to use TaskRepository instead of FeedRepository. Consider making the reviewer change check order-insensitive to avoid missing updates.

💡 Edge Case: Reviewer change check is order-sensitive

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:654-661

updateReviewers() triggers updateTaskWithNewReviewers whenever !original.getReviewers().equals(updated.getReviewers()). List.equals is order-sensitive, so a mere reordering of the same reviewers (with no actual membership change) will cause an unnecessary approval-task reassignment. Compare as sets (or via EntityUtil reference matching) to detect genuine membership changes.

✅ 4 closed
✅ Bug: Calls to TaskRepository API that does not exist in repo

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:764-768 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:836-838
KnowledgePageRepository casts Entity.getEntityRepository(Entity.TASK) to TaskRepository and calls updateApprovalTaskAssignees(...) and closeApprovalTaskForEntity(...), but a grep of the entire repository finds no TaskRepository class and no definition of either method — they appear only in this file, with no import added. As written the code will not compile. Ensure the TaskRepository class and both methods are actually added (in this PR or a merged dependency) and are on the classpath/import path, or update the call sites to the correct type.

✅ Edge Case: Possible NPE building assignees from refetched reviewers

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:757-768
updateTaskWithNewReviewers refetches the page and calls new ArrayList<>(page.getReviewers()). Although the caller guards on updated.getReviewers() != null, the re-fetched entity's reviewers are read independently and could be null, causing a NullPointerException. Guard the refetched page.getReviewers() (e.g. listOrEmpty(...)) before wrapping it.

✅ Bug: updateReviewers() override removed; reviewer reassignment lost

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:753-765
This commit deleted the updateReviewers() override in KnowledgePageUpdater, which was the only caller of updateTaskWithNewReviewers(Page). As a result, changing a KnowledgePage's reviewers no longer reassigns the open approval task, contradicting the PR's stated goal ("add updateReviewers() override to detect reviewer changes and reassign approval tasks"), and updateTaskWithNewReviewers is now unreachable dead code. Peer repositories (TagRepository, DataProductRepository, MetricRepository, DataContractRepository, GlossaryTermRepository) all retain this override. Restore the override inside KnowledgePageUpdater so it calls updateTaskWithNewReviewers(updated) when reviewers change.

✅ Quality: Unused imports will fail checkstyle/spotless build

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:20 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:36 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:55 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:63 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:73
This commit adds imports JsonPatch, CloseTask, TaskStatus, MessageParser, and WebsocketNotificationHandler, but none of these symbols are referenced anywhere in the file (each appears only on its import line). Unused imports violate the project's no-wildcard/spotless rules and will fail the checkstyle build. Remove these five imports.

🤖 Prompt for agents
Code Review: Migrates KnowledgePage approval tasks to use TaskRepository instead of FeedRepository. Consider making the reviewer change check order-insensitive to avoid missing updates.

1. 💡 Edge Case: Reviewer change check is order-sensitive
   Files: openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KnowledgePageRepository.java:654-661

   `updateReviewers()` triggers `updateTaskWithNewReviewers` whenever `!original.getReviewers().equals(updated.getReviewers())`. `List.equals` is order-sensitive, so a mere reordering of the same reviewers (with no actual membership change) will cause an unnecessary approval-task reassignment. Compare as sets (or via EntityUtil reference matching) to detect genuine membership changes.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@zhang-arvin

Copy link
Copy Markdown
Contributor Author

CI failures here (Validate PR Metadata, integration-tests-*) are fork-related: secrets aren't shared with forked PRs and the metadata check needs project fields that only repo members can set. The Java checks pass. Could a maintainer add the safe-to-test label / the required project fields?

@IceS2
IceS2 removed the request for review from a team September 14, 2026 09:57
@zhang-arvin

Copy link
Copy Markdown
Contributor Author

Maintenance note after rebasing onto current main:

This PR has been superseded upstream and cannot be cleanly rebased — the review comments here are still accurate, but the fix they ask for is now the default behaviour of main:

Given that, the correct action is to close this PR as superseded rather than rebase it — rebasing would either be a no-op or re-introduce behaviour #32912 intentionally removed. Happy to close it; leaving the decision here for a maintainer.

(gitar's finding that the old updateReviewers() override was removed is stale against the final branch head — the override is present and calls updateTaskWithNewReviewers, but that path is exactly what's obsolete now.)

@manerow

manerow commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Thanks @zhang-arvin, and sorry this waited so long for a review. You're right that it's superseded. Closing moved to TaskRepository in PR #30909 and is now a shared rule in EntityRepository (PR #34541). In #31692 we also decided to stop syncing reviewers into approval-task assignees (PR #32912), so the updateReviewers() wiring would bring back what that removed. A small correction for later readers: updateTaskReviewers() syncs a task's own reviewers when the task is edited, not a page's reviewers into its assignees. If you'd like a follow-up, we're still missing a KnowledgeCenterIT test showing that a page sent back to Draft cancels its open approval task. Happy to review it.

@manerow manerow closed this Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Knowledge page approval tasks are orphaned: KnowledgePageRepository still closes and re-assigns through the legacy feed path

2 participants