Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# An approval never goes to its requester

- **Status:** Accepted
- **Revisions:** v1 2026-11-25 (initial)
- **Revisions:** v1 2026-11-25 (initial); v2 2026-11-27 (owner fallback)
- **Deciders:** Ram Narayan Balaji
- **Guard:** `WorkflowDefinitionResourceIT.test_editorWhoIsTheOnlyApproverIsNeverAskedToApprove`,
`WorkflowDefinitionResourceIT.test_editorIsLeftOffTheApprovalWhenSomeoneElseCanApprove`,
Expand Down Expand Up @@ -39,3 +39,22 @@ review, which is the documented meaning of `none`. Revisit only if `none` itself
On upgrade, an existing workflow under `none` stops opening these tasks: an edit by the entity's
only approver, which used to wait for an admin to step in, is approved automatically. A workflow
that relied on that wait switches the node to `assignAdmins`.

## Amendment — 2026-11-27: the owner fallback

A task created with no assignee falls back to the asset's owners. Under `assignAdmins`, when the
requester is the only admin, the task stays open with no assignee and that fallback could assign the
requester. The fallback now never assigns the task's creator, the requester of a workflow task, for
every task, not only approvals. Guard: `TaskRepositoryAssigneesTest.neverFallsBackToTheTaskCreator`,
`WorkflowDefinitionResourceIT.test_taskWithoutAssigneesNeverFallsBackToItsCreator`.

The workflow builder shows each strategy with its outcome, including the owner fallback, and on a
task workflow (`noOp` trigger) shows `none` as sending the open task to the asset's owners.

On 2.0 these outcomes hold for an entity workflow's first approval step. A later step reads the
earlier step's task id: it counts as workflow-managed, copies that task's assignees and reuses that
task, so under `none` it keeps a task open instead of approving. Main fixes this with the
lifecycle-gate changes (#34693), which 2.0 does not have. The task's creator on 2.0 is the asset's
last editor, so if someone other than the requester last edited the asset, the owner fallback skips
that editor rather than the requester.

Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
import org.openmetadata.schema.api.services.CreateDatabaseService;
import org.openmetadata.schema.api.services.CreateDatabaseService.DatabaseServiceType;
import org.openmetadata.schema.api.services.DatabaseConnection;
import org.openmetadata.schema.api.tasks.CreateTask;
import org.openmetadata.schema.api.teams.CreateTeam;
import org.openmetadata.schema.api.teams.CreateUser;
import org.openmetadata.schema.api.tests.CreateTestCase;
Expand Down Expand Up @@ -13643,6 +13644,31 @@ void test_editorIsLeftOffTheApprovalWhenSomeoneElseCanApprove(
assertEquals(Set.of(colleague.getName()), assigneeNames(task));
}

@Test
void test_taskWithoutAssigneesNeverFallsBackToItsCreator(TestNamespace ns) {
OpenMetadataClient admin = SdkClients.adminClient();
User steward = createPlainUser(admin, "steward");
User colleague = createPlainUser(admin, "colleague");
DataContract contract =
createContract(
ns, List.of(steward.getEntityReference(), colleague.getEntityReference()), List.of());

Task task =
SdkClients.createClient(steward.getName(), steward.getEmail(), new String[] {})
.tasks()
.create(
new CreateTask()
.withName(ns.prefix("owner-fallback"))
.withCategory(TaskCategory.MetadataUpdate)
.withType(TaskEntityType.DescriptionUpdate)
.withAbout(
"<#E::dataContract::%s>".formatted(contract.getFullyQualifiedName())));

// With no assignees given, the task goes to the contract's owners, never to the steward who
// filed it: a filer cannot resolve their own task.
assertEquals(Set.of(colleague.getName()), assigneeNames(task));
}

private static User createPlainUser(OpenMetadataClient admin, String role) {
String name = "%s_%s".formatted(role, UUID.randomUUID().toString().substring(0, 8));
return admin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void execute(DelegateExecution execution) {
assigneeList.addAll(admins);
if (assigneeList.isEmpty()) {
LOG.warn(
"[Process: {}] Admin fallback resolved no assignees — the only platform admin is the requester; task left unassigned",
"[Process: {}] Admin fallback resolved no assignees — the only platform admin is the requester; the task falls back to the asset's owners other than the requester",
execution.getProcessInstanceId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,11 @@ private Task findActiveDataAccessRequestByCreator(String entityFqn, UUID created
/**
* If no assignees are specified and the target entity has owners, set the entity owners as default
* assignees. This ensures tasks about owned entities are automatically routed to the right people.
* The task's creator is never one of them: TaskAuthorPolicy denies a filer ResolveTask, so a task
* handed back to its creator could only be resolved by an admin
* (ADR:2026-11-25-an-approval-never-goes-to-its-requester).
*/
private void setDefaultAssigneesFromEntityOwners(Task task) {
void setDefaultAssigneesFromEntityOwners(Task task) {
if (!nullOrEmpty(task.getAssignees())) {
return;
}
Expand All @@ -466,7 +469,8 @@ private void setDefaultAssigneesFromEntityOwners(Task task) {
try {
List<EntityReference> owners = Entity.getOwners(about);
if (!nullOrEmpty(owners)) {
List<EntityReference> expandedAssignees = expandTeamsToUsers(owners);
List<EntityReference> expandedAssignees =
withoutCreator(expandTeamsToUsers(owners), task.getCreatedBy());
task.setAssignees(expandedAssignees);
LOG.debug(
"Task {} defaulting assignees to entity owners: {}",
Expand All @@ -482,6 +486,13 @@ private void setDefaultAssigneesFromEntityOwners(Task task) {
}
}

private static List<EntityReference> withoutCreator(
List<EntityReference> owners, EntityReference creator) {
final UUID creatorId = creator == null ? null : creator.getId();
return new ArrayList<>(
owners.stream().filter(owner -> !owner.getId().equals(creatorId)).toList());
}

private List<EntityReference> expandTeamsToUsers(List<EntityReference> refs) {
List<EntityReference> expanded = new ArrayList<>();
for (EntityReference ref : refs) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.openmetadata.service.jdbi3;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;

import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.openmetadata.schema.entity.tasks.Task;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.service.Entity;

class TaskRepositoryAssigneesTest {
private final TaskRepository repository = mock(TaskRepository.class, CALLS_REAL_METHODS);
private final EntityReference owner =
new EntityReference().withId(UUID.randomUUID()).withType(Entity.USER).withName("owner");
private final EntityReference about =
new EntityReference().withId(UUID.randomUUID()).withType(Entity.DOMAIN);

@Test
void defaultsUnassignedTasksToOwners() {
final Task task = new Task().withAbout(about).withAssignees(List.of());

resolveAssignees(task, List.of(owner));

assertEquals(List.of(owner), task.getAssignees());
}

@Test
void neverFallsBackToTheTaskCreator() {
final Task task = new Task().withAbout(about).withAssignees(List.of()).withCreatedBy(owner);

resolveAssignees(task, List.of(owner));

assertTrue(task.getAssignees().isEmpty());
}

@Test
void fallsBackToTheOtherOwnersWhenTheCreatorIsOneOfThem() {
final EntityReference otherOwner =
new EntityReference().withId(UUID.randomUUID()).withType(Entity.USER).withName("other");
final Task task = new Task().withAbout(about).withAssignees(List.of()).withCreatedBy(owner);

resolveAssignees(task, List.of(owner, otherOwner));

assertEquals(List.of(otherOwner), task.getAssignees());
}

@Test
void preservesExplicitAssignees() {
final EntityReference assignee =
new EntityReference().withId(UUID.randomUUID()).withType(Entity.USER).withName("reviewer");
final Task task = new Task().withAbout(about).withAssignees(List.of(assignee));

resolveAssignees(task, List.of(owner));

assertEquals(List.of(assignee), task.getAssignees());
}

private void resolveAssignees(final Task task, final List<EntityReference> owners) {
try (final var entities = mockStatic(Entity.class)) {
entities.when(() -> Entity.getOwners(about)).thenReturn(owners);
repository.setDefaultAssigneesFromEntityOwners(task);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
import { expect, test as base, type Page } from '@playwright/test';
import { SidebarItem } from '../../../constant/sidebar';
import { performAdminLogin } from '../../../utils/admin';
import { clickOutside, redirectToHomePage, uuid } from '../../../utils/common';
import {
chooseSelectOption,
clickOutside,
redirectToHomePage,
uuid,
} from '../../../utils/common';
import { waitForAllLoadersToDisappear } from '../../../utils/entity';
import { sidebarClick } from '../../../utils/sidebar';

Expand Down Expand Up @@ -43,6 +48,12 @@ async function navigateToWorkflowsListPage(page: Page) {
await waitForAllLoadersToDisappear(page);
}

// The edit test switches the approval step to Assign admins. The workflow runs only on a table
// update that changes this field, which no table has, so tables other workers create or edit while
// it is deployed never open an admin task. A trigger filter would do the same, but it disables the
// start node's add-filter button that a test below checks.
const NO_SUCH_TABLE_FIELD = 'pwOssNoSuchField';

async function navigateToWorkflowDetailPage(page: Page, name: string) {
await navigateToWorkflowsListPage(page);
await clickOutside(page);
Expand Down Expand Up @@ -127,9 +138,9 @@ if (process.env.PLAYWRIGHT_IS_OSS) {
type: 'eventBasedEntity',
config: {
entityTypes: ['table'],
events: ['Created'],
events: ['Updated'],
exclude: [],
include: [],
include: [NO_SUCH_TABLE_FIELD],
filter: {},
},
output: ['relatedEntity', 'updatedBy'],
Expand Down Expand Up @@ -369,7 +380,7 @@ if (process.env.PLAYWRIGHT_IS_OSS) {
await expect(sidebar).not.toBeVisible();
});

test('editing a form field and saving node config then workflow fires PUT API with updated data', async ({
test('editing the threshold and the no-approver strategy then saving fires PUT API with both', async ({
page,
}) => {
await redirectToHomePage(page);
Expand All @@ -384,9 +395,27 @@ if (process.env.PLAYWRIGHT_IS_OSS) {
await expect(thresholdInput).toBeEnabled();
await thresholdInput.fill('2');

const strategyTrigger = sidebar
.getByTestId('user-approval-empty-assignee-strategy-select')
.getByRole('button');

await expect(strategyTrigger).toBeEnabled();
await chooseSelectOption(
strategyTrigger,
page.getByTestId(
'user-approval-empty-assignee-strategy-assignAdmins'
),
strategyTrigger.filter({ hasText: 'Assign to admins' })
);

await sidebar.getByTestId('save-node-configuration-button').click();
await expect(sidebar).not.toBeVisible();

const saveRequest = page.waitForRequest(
(request) =>
request.url().includes('/api/v1/governance/workflowDefinitions') &&
request.method() === 'PUT'
);
const saveResponse = page.waitForResponse(
(response) =>
response.url().includes('/api/v1/governance/workflowDefinitions') &&
Expand All @@ -395,10 +424,41 @@ if (process.env.PLAYWRIGHT_IS_OSS) {
);

await page.getByTestId('save-workflow-button').click();

const savedWorkflow = (await saveRequest).postDataJSON();

expect(savedWorkflow.trigger.config.include).toEqual([
NO_SUCH_TABLE_FIELD,
]);

const savedApprovalNode = (
savedWorkflow.nodes as Array<{
name: string;
config?: {
approvalThreshold?: number;
assignees?: { emptyAssigneeStrategy?: string };
};
}>
).find((node) => node.name === 'ApprovalTask');

expect(savedApprovalNode?.config?.approvalThreshold).toBe(2);
expect(
savedApprovalNode?.config?.assignees?.emptyAssigneeStrategy
).toBe('assignAdmins');

await saveResponse;
await waitForAllLoadersToDisappear(page);

await expect(page.getByTestId('edit-workflow-button')).toBeVisible();

await navigateToWorkflowDetailPage(page, workflowName);
const reopenedSidebar = await openTaskNodeSidebar(page);

await expect(
reopenedSidebar
.getByTestId('user-approval-empty-assignee-strategy-select')
.getByRole('button')
).toContainText('Assign to admins');
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2026 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { EmptyAssigneeStrategy } from '../../../../generated/governance/workflows/elements/nodes/userTask/userApprovalTask';

export const EMPTY_ASSIGNEE_STRATEGY_OPTIONS: Record<
EmptyAssigneeStrategy,
{ labelKey: string; hintKey: string }
> = {
[EmptyAssigneeStrategy.None]: {
labelKey: 'label.approve-automatically',
hintKey: 'message.empty-assignee-strategy-none-hint',
},
[EmptyAssigneeStrategy.AssignAdmins]: {
labelKey: 'label.assign-to-admins',
hintKey: 'message.empty-assignee-strategy-assign-admins-hint',
},
};

// A task workflow (noOp trigger) never approves on its own: with none, its task stays open and the
// owner fallback assigns the asset's owners.
export const NONE_IN_TASK_WORKFLOW_OPTION = {
labelKey: 'label.go-to-asset-owners',
hintKey: 'message.empty-assignee-strategy-none-task-workflow-hint',
};

// The default comes first; the generated enum is alphabetical.
export const SELECTABLE_EMPTY_ASSIGNEE_STRATEGIES: EmptyAssigneeStrategy[] = [
EmptyAssigneeStrategy.None,
EmptyAssigneeStrategy.AssignAdmins,
];
Loading
Loading