{"record":{"id":"5ae4585252900740","repo":"instructure/canvas-lms","slug":"not-found-apply-institutional-tag","errorCode":null,"errorMessage":"not found","messagePattern":"not found","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/apply_institutional_tag.rb","lineNumber":42,"sourceCode":"  class ApplyInstitutionalTag < BaseMutation\n    argument :tag_id,\n             ID,\n             required: true,\n             prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func(\"InstitutionalTag\")\n    argument :user_id,\n             ID,\n             required: true,\n             prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func(\"User\")\n\n    field :institutional_tag_association, Types::InstitutionalTagAssociationType, null: true\n\n    def resolve(input:) # rubocop:disable GraphQL/UnusedArgument\n      root_account = context[:domain_root_account]\n      raise GraphQL::ExecutionError, \"feature flag is disabled\" unless root_account.feature_enabled?(:institutional_tags)\n      raise GraphQL::ExecutionError, \"not authorized\" unless root_account.grants_right?(current_user, session, :manage_institutional_tags_edit)\n\n      tag = InstitutionalTag.where(root_account_id: root_account.id, workflow_state: \"active\").find_by(id: input[:tag_id])\n      raise GraphQL::ExecutionError, \"not found\" unless tag\n\n      user = root_account.all_users.find_by(id: input[:user_id])\n      raise GraphQL::ExecutionError, \"not found\" unless user\n\n      assoc = InstitutionalTagAssociation.find_or_initialize_by(\n        institutional_tag: tag,\n        context: user,\n        root_account:\n      )\n      assoc.workflow_state = \"active\"\n\n      if assoc.save\n        { institutional_tag_association: assoc }\n      else\n        errors_for(assoc)\n      end\n    end\n  end","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/apply_institutional_tag.rb#L24-L60","documentation":"Raised when no active InstitutionalTag with the given tag_id exists on this root account. Lookup is `InstitutionalTag.where(root_account_id:, workflow_state: \"active\").find_by(id: input[:tag_id])`, so deleted/inactive tags or wrong-account ids fail.","triggerScenarios":"Passing a tag_id belonging to a different root account; the tag was deactivated (workflow_state != 'active') or deleted; tag_id is a legacy/global id not convertible by the relay/legacy id prepare function; typo'd or stale id cached on the client.","commonSituations":"Using a tag id from a test environment in prod; referencing a tag that was archived after being created; passing the internal DB id when the argument expects a relay/legacy prepared id; re-running an old automation script after the tag was deactivated.","solutions":["Verify the tag exists and is active: `InstitutionalTag.find_by(id:, root_account_id:, workflow_state: 'active')` in console.","Create or re-activate the tag on the correct root account before calling the mutation.","Use the correct global/relay id for the tag argument.","Confirm you're operating on the same root account (shard) that owns the tag."],"exampleFix":"// before\napplyInstitutionalTag(input: { tagId: 123, userId: 456 }) # tag inactive or wrong account\n\n// after: check first\ntag = InstitutionalTag.find_by(id: 123, root_account_id: account.id, workflow_state: 'active')\n# only call the mutation if tag present","handlingStrategy":"validation","validationCode":"tag = InstitutionalTag.find_by(id: tag_id, root_account_id: account.id, workflow_state: 'active')\nraise 'tag not found/inactive' unless tag\n","typeGuard":null,"tryCatchPattern":"begin\n  apply_tag(tag_id:, user_id:)\nrescue GraphQL::ExecutionError => e\n  refresh_tag_list if e.message == 'not found'\nend","preventionTips":["Fetch fresh tag lists before mutating","Filter UI dropdowns to active tags only","Never hardcode tag ids across environments"],"tags":["graphql","not-found","canvas-lms","resource-lookup"],"backgroundTag":"record-not-found","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}