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 anotherView on GitHub (pinned to 988cbb0330)
Solutions
- Populate ownerType/ownerID from the authenticated principal or owning entity before calling Bind
- Validate both fields with strings.TrimSpace before the call
- Return a 400-style error upstream when owner metadata is missing from the request
- 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
- Validate owner fields at the request-decoding layer
- Make ownerType/ownerID required params in your service's own API
- Use non-zero defaults for service-owned resources
- Unit test Bind with zero-value owner structs
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
- member_limit must be >= 0
- missing query parameter
- no queries provided
- missing id parameter
- knowledge_base_ids is required
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/aa57d95eca46a5a5.
Report an issue: GitHub.