Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: prevent auto-incrementing memory name suffix when only permissions change (#16750)

euvre74d3508a378a
diff --git a/api/db/services/memory_service.py b/api/db/services/memory_service.py
index 495f0fb1c8..5dab6361df 100644
--- a/api/db/services/memory_service.py
+++ b/api/db/services/memory_service.py
@@ -154,7 +154,9 @@ class MemoryService(CommonService):
update_dict["memory_type"] = calculate_memory_type(update_dict["memory_type"])
if "name" in update_dict:
existing = cls.model.select().where((cls.model.id == memory_id) & (cls.model.tenant_id == tenant_id)).first()
- if not existing or existing.name != update_dict["name"]:
+ if existing and existing.name == update_dict["name"]:
+ update_dict.pop("name", None)
+ else:
update_dict["name"] = duplicate_name(cls.query, name=update_dict["name"], tenant_id=tenant_id)
update_dict.update({"update_time": current_timestamp(), "update_date": get_format_time()})
diff --git a/internal/service/memory.go b/internal/service/memory.go
index ae194921be..96011140c5 100644
--- a/internal/service/memory.go
+++ b/internal/service/memory.go
@@ -452,19 +452,26 @@ func (s *MemoryService) CreateMemory(tenantID string, req *CreateMemoryRequest)
func (s *MemoryService) UpdateMemory(tenantID string, memoryID string, req *UpdateMemoryRequest) (*CreateMemoryResponse, error) {
updateDict := make(map[string]interface{})
+ currentMemory, err := s.memoryDAO.GetByID(memoryID)
+ if err != nil {
+ return nil, fmt.Errorf("memory '%s' not found", memoryID)
+ }
+
if req.Name != nil {
memoryName := strings.TrimSpace(*req.Name)
if err := common.ValidateName(memoryName); err != nil {
return nil, err
}
- memoryName, err := common.DuplicateName(func(name string, tid string) bool {
- existing, _ := s.memoryDAO.GetByNameAndTenant(name, tid)
- return len(existing) > 0
- }, memoryName, tenantID)
- if err != nil {
- return nil, err
+ if memoryName != strings.TrimSpace(currentMemory.Name) {
+ memoryName, err := common.DuplicateName(func(name string, tid string) bool {
+ existing, _ := s.memoryDAO.GetByNameAndTenant(name, tid)
+ return len(existing) > 0
+ }, memoryName, tenantID)
+ if err != nil {
+ return nil, err
+ }
+ updateDict["name"] = memoryName
}
- updateDict["name"] = memoryName
}
if req.Permissions != nil {
@@ -552,11 +559,6 @@ func (s *MemoryService) UpdateMemory(tenantID string, memoryID string, req *Upda
}
}
- currentMemory, err := s.memoryDAO.GetByID(memoryID)
- if err != nil {
- return nil, fmt.Errorf("memory '%s' not found", memoryID)
- }
-
if len(updateDict) == 0 {
return formatRetDataFromMemory(currentMemory), nil
}