Tencent/WeKnora · error

resource binding requires owner type and id

Error message

resource binding requires owner type and id

What it means

Bind refuses to create a resource binding when ownerType or ownerID is blank. Every binding must record which entity owns the resource and how; without both, the binding row would be unattributable and unusable for later Release/ownership checks. Thrown after the reference itself resolves successfully.

Source

Thrown at internal/application/service/resource.go:144

func (s *resourceCatalog) ResolvePath(ctx context.Context, value string) (string, *types.StoredResource, error) {
	if _, ok := types.ParseResourcePath(value); !ok {
		return value, nil, nil
	}
	resource, err := s.Resolve(ctx, value)
	if err != nil {
		return "", nil, err
	}
	return resource.PhysicalPath, resource, nil
}

func (s *resourceCatalog) Bind(ctx context.Context, reference, ownerType, ownerID, relation string) error {
	resource, err := s.Resolve(ctx, reference)
	if err != nil {
		return err
	}
	if strings.TrimSpace(ownerType) == "" || strings.TrimSpace(ownerID) == "" {
		return fmt.Errorf("resource binding requires owner type and id")
	}
	if relation == "" {
		relation = "attachment"
	}
	return s.repo.CreateBinding(ctx, &types.ResourceBinding{
		ResourceID: resource.ID,
		TenantID:   resource.TenantID,
		OwnerType:  ownerType,
		OwnerID:    ownerID,
		Relation:   relation,
	})
}

// Release implements interfaces.ResourceCatalog.
//
// Unbinding and counting are deliberately not a single transaction. A racing
// bind that lands between them makes the count too high, which keeps a live
// file — the safe direction. The opposite ordering could delete bytes another

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Populate ownerType/ownerID from the authenticated principal or owning entity before calling Bind
  2. Validate both fields with strings.TrimSpace before the call
  3. Return a 400-style error upstream when owner metadata is missing from the request
  4. Default the owner to a system principal if the resource is genuinely service-owned

Example fix

// before
catalog.Bind(ctx, ref, cfg.OwnerType, cfg.OwnerID, "attachment")
// after
if strings.TrimSpace(cfg.OwnerType) == "" || strings.TrimSpace(cfg.OwnerID) == "" {
    return fmt.Errorf("owner metadata required")
}
catalog.Bind(ctx, ref, cfg.OwnerType, cfg.OwnerID, "attachment")
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(ownerType) == "" || strings.TrimSpace(ownerID) == "" {
    return errors.New("owner type and id are required")
}

Type guard

func hasOwner(o Owner) bool { return strings.TrimSpace(o.Type) != "" && strings.TrimSpace(o.ID) != "" }

Try / catch

err := catalog.Bind(ctx, ref, ownerType, ownerID, rel)
if err != nil && strings.Contains(err.Error(), "requires owner type and id") {
    return ErrMissingOwner
}

Prevention

When it happens

Trigger: Calling Bind(ctx, ref, "", "", rel) or passing whitespace-only owner fields, often from unmarshaled config or optional struct fields left unset.

Common situations: Zero-value struct fields when the owner object failed to hydrate; empty string from an optional request field; forgetting to set owner fields when binding service-owned resources.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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