{"record":{"id":"379f4bea14ad545c","repo":"iflytek/astron-agent","slug":"app-tenant-not-found-error-id-is-a","errorCode":"APP_TENANT_NOT_FOUND_ERROR","errorMessage":"{tenant_app_id} is not a tenant","messagePattern":"(.+?) is not a tenant","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/workflow/service/auth_service.py","lineNumber":36,"sourceCode":"\n    This function validates tenant permissions, checks workflow publish status,\n    and registers the binding relationship in the license table.\n\n    :param session: Database session for data operations\n    :param tenant_app_id: Tenant application ID for validation\n    :param auth_input: Authentication input containing app_id and flow_id\n    :param span: Distributed tracing span for monitoring\n    :return: None\n    :raises CustomException: When tenant not found, flow not found,\n            or flow not published\n    \"\"\"\n    user_app_id = auth_input.app_id\n\n    # Validate tenant application exists and is a tenant\n    db_tenant_app = await app_service.get_info(tenant_app_id, session, span)\n    if not db_tenant_app.is_tenant:\n        await span.add_info_event_async(f\"Tenant app ID: {tenant_app_id}\")\n        raise CustomException(\n            CodeEnum.APP_TENANT_NOT_FOUND_ERROR,\n            err_msg=f\"{tenant_app_id} is not a tenant\",\n        )\n\n    # Get user application information\n    db_app = await app_service.get_info(user_app_id, session, span)\n\n    # Validate workflow exists\n    db_flow = session.query(Flow).filter_by(id=auth_input.flow_id).first()\n    if not db_flow:\n        await span.add_info_event_async(f\"Flow ID: {auth_input.flow_id}\")\n        raise CustomException(CodeEnum.FLOW_NOT_FOUND_ERROR)\n\n    group_id = db_flow.group_id\n    release_status = (\n        db_flow.release_status\n    )  # Current workflow publish permissions across platforms\n    rs = TenantPublishMatrix(","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/service/auth_service.py#L18-L54","documentation":"APP_TENANT_NOT_FOUND_ERROR raised in auth_service.handle after get_info succeeds but the resolved app has is_tenant=False. The referenced app exists but is not marked as a tenant app, which the auth flow requires as the caller context.","triggerScenarios":"Calling the auth flow with a tenant_app_id whose AppSource.is_tenant flag is false — i.e., an ordinary user app passed where a tenant app is required.","commonSituations":"Swapping tenant_app_id and user_app_id arguments, using a user-level app as the tenant context, the app's is_tenant flag not being set during provisioning.","solutions":["Verify tenant_app_id refers to an app with is_tenant=true in the app_source table","Set is_tenant=true on the intended tenant app if it should be a tenant","Check argument order — don't pass the user app_id as tenant_app_id","Re-provision the tenant app on the management platform with tenant type"],"exampleFix":"// before\nauth_input = AuthInput(app_id=user_app_id)  # not a tenant\n// after\nauth_input = AuthInput(app_id=tenant_app_id)  # app with is_tenant=true","handlingStrategy":"validation","validationCode":"db_app = session.query(AppSource).filter_by(source_id=tenant_app_id).first()\nif not db_app or not db_app.is_tenant:\n    raise ValueError(f'{tenant_app_id} is not a tenant app')","typeGuard":null,"tryCatchPattern":"try:\n    result = await auth_service.handle(auth_input, session, span)\nexcept CustomException as e:\n    if e.err_code == CodeEnum.APP_TENANT_NOT_FOUND_ERROR and 'is not a tenant' in e.err_msg:\n        return error_response(400, 'tenant_app_id must reference a tenant app')\n    raise","preventionTips":["Store tenant_app_id and user_app_id in separate, clearly named config fields","Verify is_tenant=true during tenant app provisioning","Add a startup/config check that the configured tenant app is actually a tenant","Never pass user apps as the tenant context in auth flows"],"tags":["auth","tenant","app-config"],"backgroundTag":"invalid-argument-value","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}