{"record":{"id":"b6135ec1b2aa468f","repo":"instructure/canvas-lms","slug":"outcome-with-id-guid-already-exists-in-another-unrelated","errorCode":null,"errorMessage":"Outcome with ID %{guid} already exists in another unrelated course or account (%{name})","messagePattern":"Outcome with ID %(.+?) already exists in another unrelated course or account \\(%(.+?)\\)","errorType":"exception","errorClass":"InvalidDataError","httpStatus":null,"severity":"error","filePath":"lib/outcomes/import.rb","lineNumber":156,"sourceCode":"      model\n    end\n\n    def import_outcome(outcome)\n      invalid = outcome.keys.select do |k|\n        outcome[k].present? && GROUP_ONLY_FIELDS.include?(k)\n      end\n      if invalid.present?\n        raise InvalidDataError, I18n.t(\n          \"Invalid fields for an outcome: %{invalid}\",\n          invalid: invalid.map(&:to_s).inspect\n        )\n      end\n\n      model = find_prior_outcome(outcome)\n      model.context = context if model.new_record?\n\n      unless child_context?(context, of: model.context)\n        raise InvalidDataError, I18n.t(\n          \"Outcome with ID %{guid} already exists in another unrelated course or account (%{name})\",\n          guid: outcome[:vendor_guid],\n          name: model.context.name\n        )\n      end\n\n      allow_indirect = outcome.key?(:course_id)\n      parents = find_parents(outcome, context, allow_indirect:)\n\n      if model.outcome_import_id == outcome_import_id\n        raise InvalidDataError, I18n.t(\n          'Outcome \"%{guid}\" has already appeared in this import',\n          guid: outcome[:vendor_guid]\n        )\n      end\n\n      model.vendor_guid = outcome[:vendor_guid]\n      model.title = outcome[:title]","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/outcomes/import.rb#L138-L174","documentation":"Raised by Outcomes::Import#import_outcome when an outcome identified by vendor_guid already exists in a context (course or account) that is not a child/ancestor of the importing context. The import refuses to touch outcomes owned by unrelated contexts, since cross-context modification would corrupt outcome ownership. The existing outcome's context name is included in the message to help locate it.","triggerScenarios":"Importing a course/account outcome export whose vendor_guid matches a LearningOutcome in a completely unrelated course or root account; child_context?(context, of: model.context) returns false in import_outcome (lib/outcomes/import.rb:156).","commonSituations":"Re-importing an outcome package originally exported from a different institution/account; a vendor_guid collision where two courses reuse the same GUID; copying outcome import files between Canvas accounts without re-keying vendor_guids.","solutions":["Check which context already owns the outcome (the %{name} in the message) and import into that context or a child of it.","Change the vendor_guid in the import file so it no longer collides with the unrelated outcome.","Delete or re-purpose the pre-existing outcome if it was created by mistake, then re-run the import.","Import the outcome at a common ancestor account so both contexts are within the same hierarchy."],"exampleFix":"// before: importing a package with vendor_guid 'X' already owned by Account A, from unrelated Account B\n// after: re-key the guid in the import JSON\n{\n  \"vendor_guid\": \"X-account-B\",\n  \"title\": \"Outcome\"\n}","handlingStrategy":"validation","validationCode":"// Ruby: pre-check ownership before importing\ndef importable?(vendor_guid, context)\n  lo = LearningOutcome.find_by(vendor_guid: vendor_guid)\n  lo.nil? || context == lo.context || context.account_chain.include?(lo.context)\nend","typeGuard":null,"tryCatchPattern":"begin\n  importer.import_object(...)\nrescue Outcomes::Import::InvalidDataError => e\n  Rails.logger.warn(\"Outcome ownership conflict: #{e.message}\")\n  # skip row or re-key guid and retry\nend","preventionTips":["Keep vendor_guids globally unique (prefix with your institution/account id).","Import only exports generated from the same account hierarchy.","Check the %{name} in the message to find the conflicting context before re-running."],"tags":["outcomes","import","context-hierarchy","duplicate-key"],"backgroundTag":"resource-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"}