apolloconfig/apollo · error · BadRequestException

Merge operation failed. Because master has modified items

Error message

Merge operation failed. Because master has modified items

What it means

Thrown as a BadRequestException by NamespaceBranchService.calculateBranchChangeSet() when merging a gray-release branch back to master, but the master namespace has uncommitted modified items (parentNamespace.getItemModifiedCnt() > 0). Apollo's merge operation requires the master to be in a clean state so that branch changes can be applied deterministically. Modified items on master would be silently overwritten, so the operation is blocked.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceBranchService.java:124

        namespaceName, title, comment, branchName, isEmergencyPublish, deleteBranch, changeSets);

    Tracer.logEvent(TracerEventType.MERGE_GRAY_RELEASE,
        String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName));

    return mergedResult;
  }

  private ItemChangeSets calculateBranchChangeSet(String appId, Env env, String clusterName,
      String namespaceName, String branchName, String operator) {
    NamespaceBO parentNamespace =
        namespaceService.loadNamespaceBO(appId, env, clusterName, namespaceName);

    if (parentNamespace == null) {
      throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName);
    }

    if (parentNamespace.getItemModifiedCnt() > 0) {
      throw new BadRequestException("Merge operation failed. Because master has modified items");
    }

    List<ItemDTO> masterItems = itemService.findItems(appId, env, clusterName, namespaceName);

    List<ItemDTO> branchItems = itemService.findItems(appId, env, branchName, namespaceName);

    ItemChangeSets changeSets = itemsComparator.compareIgnoreBlankAndCommentItem(
        parentNamespace.getBaseInfo().getId(), masterItems, branchItems);
    changeSets.setDeleteItems(Collections.emptyList());
    changeSets.setDataChangeLastModifiedBy(operator);
    return changeSets;
  }

  public NamespaceDTO findBranchBaseInfo(String appId, Env env, String clusterName,
      String namespaceName) {
    return namespaceBranchAPI.findBranch(appId, env, clusterName, namespaceName);
  }

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Publish or revert the modified items on the master namespace before retrying the merge.
  2. Review the master namespace's item changes in the portal UI and resolve them (publish or abandon).
  3. Communicate with team members to avoid concurrent edits to master while a gray release is active.
  4. If the branch changes are more important, manually reconcile master items first, then merge.
Defensive patterns

Strategy: validation

Validate before calling

// Check master namespace has no modified items before merge
NamespaceBO parentNs = namespaceService.loadNamespaceBO(appId, env, clusterName, namespaceName);
if (parentNs.getItemModifiedCnt() > 0) {
  throw new IllegalStateException(
    "Master namespace has " + parentNs.getItemModifiedCnt()
    + " modified items. Publish or revert before merging the branch.");
}

Try / catch

try {
  namespaceBranchService.merge(appId, env, clusterName, namespaceName, branchName, title, comment, isEmergency, deleteBranch, operator);
} catch (BadRequestException e) {
  if (e.getMessage().contains("master has modified items")) {
    log.warn("Merge blocked: master has uncommitted changes. Publish master first.");
    // surface guidance to the user
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling NamespaceBranchService.merge() (the gray-release merge API) when the parent/master namespace has items with a modified status. The merge flow loads the parent NamespaceBO, checks itemModifiedCnt, and rejects if greater than zero before computing the change set.

Common situations: Another user edited items on the master namespace after the gray branch was created; a previous publish on master left items in modified state; concurrent edits to master while a merge is in progress; stale branch that predates master changes.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/71cf9db83b02493e. Report an issue: GitHub.