{"record":{"id":"71cf9db83b02493e","repo":"apolloconfig/apollo","slug":"merge-operation-failed-because-master-has-modifie","errorCode":null,"errorMessage":"Merge operation failed. Because master has modified items","messagePattern":"Merge operation failed\\. Because master has modified items","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceBranchService.java","lineNumber":124,"sourceCode":"        namespaceName, title, comment, branchName, isEmergencyPublish, deleteBranch, changeSets);\n\n    Tracer.logEvent(TracerEventType.MERGE_GRAY_RELEASE,\n        String.format(\"%s+%s+%s+%s\", appId, env, clusterName, namespaceName));\n\n    return mergedResult;\n  }\n\n  private ItemChangeSets calculateBranchChangeSet(String appId, Env env, String clusterName,\n      String namespaceName, String branchName, String operator) {\n    NamespaceBO parentNamespace =\n        namespaceService.loadNamespaceBO(appId, env, clusterName, namespaceName);\n\n    if (parentNamespace == null) {\n      throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName);\n    }\n\n    if (parentNamespace.getItemModifiedCnt() > 0) {\n      throw new BadRequestException(\"Merge operation failed. Because master has modified items\");\n    }\n\n    List<ItemDTO> masterItems = itemService.findItems(appId, env, clusterName, namespaceName);\n\n    List<ItemDTO> branchItems = itemService.findItems(appId, env, branchName, namespaceName);\n\n    ItemChangeSets changeSets = itemsComparator.compareIgnoreBlankAndCommentItem(\n        parentNamespace.getBaseInfo().getId(), masterItems, branchItems);\n    changeSets.setDeleteItems(Collections.emptyList());\n    changeSets.setDataChangeLastModifiedBy(operator);\n    return changeSets;\n  }\n\n  public NamespaceDTO findBranchBaseInfo(String appId, Env env, String clusterName,\n      String namespaceName) {\n    return namespaceBranchAPI.findBranch(appId, env, clusterName, namespaceName);\n  }\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceBranchService.java#L106-L142","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Publish or revert the modified items on the master namespace before retrying the merge.","Review the master namespace's item changes in the portal UI and resolve them (publish or abandon).","Communicate with team members to avoid concurrent edits to master while a gray release is active.","If the branch changes are more important, manually reconcile master items first, then merge."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Check master namespace has no modified items before merge\nNamespaceBO parentNs = namespaceService.loadNamespaceBO(appId, env, clusterName, namespaceName);\nif (parentNs.getItemModifiedCnt() > 0) {\n  throw new IllegalStateException(\n    \"Master namespace has \" + parentNs.getItemModifiedCnt()\n    + \" modified items. Publish or revert before merging the branch.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  namespaceBranchService.merge(appId, env, clusterName, namespaceName, branchName, title, comment, isEmergency, deleteBranch, operator);\n} catch (BadRequestException e) {\n  if (e.getMessage().contains(\"master has modified items\")) {\n    log.warn(\"Merge blocked: master has uncommitted changes. Publish master first.\");\n    // surface guidance to the user\n  }\n  throw e;\n}","preventionTips":["Publish or revert all modified items on the master namespace before initiating a merge.","Coordinate with team members to avoid editing master while a gray release is active.","Check the master namespace's modified-item count in the UI before clicking merge."],"tags":["apollo-portal","gray-release","merge","bad-request","namespace","conflict"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}