Tencent/WeKnora · error

wiki page version conflict

Error message

wiki page version conflict

What it means

Sentinel ErrWikiPageConflict returned by UpdateWithRevision when the optimistic-lock check fails: the row's current version no longer equals the caller's expected version (stale write). The rejected write must not bump the version or create a revision. Typically surfaced as 409.

Source

Thrown at internal/application/repository/wiki_page.go:21

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"strings"
	"time"

	"github.com/Tencent/WeKnora/internal/types"
	"github.com/Tencent/WeKnora/internal/types/interfaces"
	"gorm.io/gorm"
	"gorm.io/gorm/clause"
)

// ErrWikiPageNotFound is returned when a wiki page is not found
var ErrWikiPageNotFound = errors.New("wiki page not found")

// ErrWikiPageConflict is returned when an optimistic lock conflict is detected
var ErrWikiPageConflict = errors.New("wiki page version conflict")

// wikiPageRepository implements the WikiPageRepository interface
type wikiPageRepository struct {
	db *gorm.DB
}

// NewWikiPageRepository creates a new wiki page repository
func NewWikiPageRepository(db *gorm.DB) interfaces.WikiPageRepository {
	return &wikiPageRepository{db: db}
}

func (r *wikiPageRepository) wikiCategoryRankOrder() string {
	if r.db != nil && r.db.Dialector != nil && r.db.Dialector.Name() == "sqlite" {
		return "CASE WHEN COALESCE(json_array_length(category_path), 0) > 0 THEN 0 ELSE 1 END ASC"
	}
	return "CASE WHEN COALESCE(jsonb_array_length(category_path), 0) > 0 THEN 0 ELSE 1 END ASC"
}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Reload the page to get the latest version, reapply the edit, and resubmit
  2. Show a merge/conflict UI to the user instead of overwriting the newer revision
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/application/repository/wiki_page.go:21 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/2c72f24dda209f75. Report an issue: GitHub.