siyuan-note/siyuan · error
attribute view item markdown is nil
Error message
attribute view item markdown is nil
What it means
CreateAttributeViewItemWithMarkdown creates a database row and a bound document from the supplied Markdown payload. The document parameter is mandatory; passing nil gives the function no content template, so it rejects the call before touching the attribute view.
Source
Thrown at kernel/model/attribute_view_new_item.go:89
// CreateAttributeViewItemDocsResult 描述将游离条目批量转换为文档后的结果。
type CreateAttributeViewItemDocsResult struct {
ItemIDs []string `json:"itemIDs"`
BlockIDs []string `json:"blockIDs"`
SkippedItemIDs []string `json:"skippedItemIDs,omitempty"`
Warnings []string `json:"warnings,omitempty"`
Transaction *Transaction `json:"-"`
}
// CreateAttributeViewItem 按指定模板创建一个数据库条目。templateID 为空时创建空白游离条目。
func CreateAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID string) (*CreateAttributeViewItemResult, error) {
return createAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID, nil)
}
// CreateAttributeViewItemWithMarkdown 按指定的文档类型模板创建数据库条目,并使用传入的 Markdown 创建绑定文档。
func CreateAttributeViewItemWithMarkdown(avID, blockID, viewID, templateID, previousID, groupID string,
document *CreateAttributeViewItemMarkdown) (*CreateAttributeViewItemResult, error) {
if nil == document {
return nil, errors.New("attribute view item markdown is nil")
}
return createAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID, document)
}
func createAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID string,
document *CreateAttributeViewItemMarkdown) (*CreateAttributeViewItemResult, error) {
attrView, err := avParseView(avID, blockID)
if nil != err {
return nil, err
}
createdAt := time.Now()
itemTemplate := attrView.GetNewItemTemplate(templateID)
var prunedOptions []*av.PrunedNewItemTemplateOption
if "" != templateID && nil == itemTemplate {
return nil, fmt.Errorf("new item template [%s] not found", templateID)
}
if nil == itemTemplate {
itemTemplate = &av.NewItemTemplate{TargetType: av.NewItemTargetDetached}View on GitHub (pinned to 8641553a1f)
Solutions
- Construct a *CreateAttributeViewItemMarkdown with at least the Markdown content (and Title if desired) before calling
- If you do not need Markdown-bound documents, call CreateAttributeViewItem instead, which has no document requirement
- In the API handler, validate the request payload's document field is present
Example fix
// before
res, err := model.CreateAttributeViewItemWithMarkdown(avID, blockID, viewID, tplID, "", "", nil)
// after
doc := &model.CreateAttributeViewItemMarkdown{Title: "New Item", Markdown: "# New Item\ncontent"}
res, err := model.CreateAttributeViewItemWithMarkdown(avID, blockID, viewID, tplID, "", "", doc) Defensive patterns
Strategy: validation
Validate before calling
if document == nil {
return errors.New("a Markdown document payload is required")
} Type guard
func hasMarkdownDoc(d *model.CreateAttributeViewItemMarkdown) bool { return d != nil } Try / catch
res, err := model.CreateAttributeViewItemWithMarkdown(avID, blockID, viewID, tplID, "", "", doc)
if err != nil {
return fmt.Errorf("create item with markdown: %w", err)
} Prevention
- Construct the document struct at the call site, never forward a possibly-nil pointer
- Unmarshal API request bodies into concrete structs and reject missing document fields
- Use CreateAttributeViewItem when no Markdown binding is needed
When it happens
Trigger: Calling CreateAttributeViewItemWithMarkdown with document=nil (the *CreateAttributeViewItemMarkdown pointer is nil).
Common situations: A caller that conditionally builds the document struct but hits a branch where it stays nil; JSON unmarshaling of the request body produced a nil object because the field was absent; copy-paste from CreateAttributeViewItem which takes no document parameter.
Related errors
- parent ID is required
- previous ID and next ID cannot both be specified
- attribute view is required
- view not found
- key not found
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/9f69067f42ac7d8f.
Report an issue: GitHub.