infiniflow/ragflow · error · GroupValidationError

Template {child_id} does not belong to this group.

Error message

Template {child_id} does not belong to this group.

What it means

Raised while updating a compilation template group when a submitted child template carries an id that does not match any existing VALID template row in that group (current_by_id lookup fails). It is a referential-integrity guard: child ids must reference templates already belonging to the same group_id and tenant.

Source

Thrown at api/db/services/compilation_template_group_service.py:315

            if templates is not None:
                current_children = list(
                    CompilationTemplate.select()
                    .where(
                        CompilationTemplate.group_id == group_id,
                        CompilationTemplate.status == StatusEnum.VALID.value,
                    )
                    .order_by(CompilationTemplate.create_time.asc())
                )
                current_by_id = {child.id: child for child in current_children}
                retained_ids: set[str] = set()
                seen_names: set[str] = set()

                for index, child in enumerate(templates):
                    child_id = str((child or {}).get("id") or "").strip()
                    target = current_by_id.get(child_id) if child_id else None
                    if child_id and target is None:
                        raise GroupValidationError(f"Template {child_id} does not belong to this group.")
                    # Older clients did not send child ids. Preserve their
                    # existing ids by matching the submitted order.
                    if target is None and not child_id and index < len(current_children):
                        target = current_children[index]

                    kind = str((child or {}).get("kind") or "").strip()
                    name = str((child or {}).get("name") or "").strip()
                    config = (child or {}).get("config") or {}
                    if not kind or not name or not isinstance(config, dict):
                        raise GroupValidationError("Each template must include a name, kind, and config object.")
                    if name in seen_names:
                        raise GroupValidationError(f"Template name '{name}' is duplicated in this group.")
                    seen_names.add(name)

                    from api.db.services.compilation_template_service import CompilationTemplateService

                    config = CompilationTemplateService.fill_config_default_llm(config, tenant_id)
                    duplicate_query = CompilationTemplate.select().where(

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Refetch the group and its templates to get current ids before submitting the update.
  2. If adding a brand-new template, omit the id field entirely — the server assigns one (or falls back to positional matching for legacy clients without ids).
  3. If the template was deleted, re-create it instead of submitting its old id.

Example fix

// before
{"id": "stale-or-foreign-template-id", "name": "T", "kind": "tree", "config": {}}
// after (new template: no id)
{"name": "T", "kind": "tree", "config": {}}
Defensive patterns

Strategy: validation

Validate before calling

current = {t.id for t in fetch_group_templates(group_id)}
for t in payload['templates']:
    tid = str(t.get('id') or '').strip()
    if tid and tid not in current:
        raise ValueError(f'stale child id {tid}; refetch group')

Try / catch

try:
    save_group(group_id, payload)
except GroupValidationError as e:
    if 'does not belong to this group' in str(e):
        payload = refresh_ids_and_retry(group_id, payload)  # refetch then resubmit
    else:
        raise

Prevention

When it happens

Trigger: Group update API call where a template entry includes a non-empty id that is not among the group's current VALID children — e.g. an id from another group, a deleted/soft-deleted template, or a stale id from before the group was recreated.

Common situations: Editing a group in one browser tab after the template was removed or moved in another; frontend caching old template ids after a group restructure; copying group JSON between environments where ids differ.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/a3d9faa777f3f23a. Report an issue: GitHub.