Uploaded image for project: 'SR for Jira - Development'
  1. SR for Jira - Development
  2. SRJIRA-4374

AddMissingScriptFieldConfigurationsUpgradeTask can skip custom fields

    Details

    • Type: Bug
    • Status: Done (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 6.2.1
    • Component/s: None
    • Labels:
      None
    • Critical Points:
      7.4

      Description

      After upgrading users cannot create issues. You will see the error 

      Caused by: java.lang.Exception: Missing parameters for fields
      

       in the logs. 

      Workaround:

      Do not downgrade. Downgrading is not supported and will cause further issues in your Jira instance. 

      Please make sure you have re-upgraded to at least 6.1.0 and run this script in the script console:

      import com.atlassian.jira.component.ComponentAccessor
      import com.onresolve.scriptrunner.canned.jira.fields.editable.ScriptField
      import com.onresolve.scriptrunner.fields.ScriptFieldManager
      import com.onresolve.scriptrunner.fields.ScriptFieldManagerImpl
      import com.onresolve.scriptrunner.fields.ScriptFieldsStorage
      import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
      import static com.onresolve.scriptrunner.JiraPluginKeyProvider.JIRA_PLUGIN_KEY
      
      def scriptFieldManager = ScriptRunnerImpl.scriptRunner.getBean(ScriptFieldManager)
      def scriptFieldsStorage = ScriptRunnerImpl.scriptRunner.getBean(ScriptFieldsStorage)
      def customFieldManager = ComponentAccessor.customFieldManager
      
      customFieldManager.getCustomFieldObjects().findAll {
          if (it.customFieldType.descriptor.completeKey ==  JIRA_PLUGIN_KEY + ":jqlFunctionsCustomFieldType") {
              return false
          }
          it.customFieldType.descriptor.completeKey.startsWith(JIRA_PLUGIN_KEY)
      }.each{ customField ->
          if (scriptFieldManager.getConfigFor(customField)) {
              return
          }
          def customFieldType = customField.customFieldType
          if (customFieldType instanceof ScriptField) {
              try {
                  def config = customFieldType.getCommandObject()
                  config.customFieldId = customField.idAsLong
                  config.fieldConfigurationSchemeId = customField.configurationSchemes ?
                      customField.configurationSchemes.first().id : -1L
                  log.info("Adding script field config for '$customField.name'")
                  scriptFieldsStorage.save(scriptFieldsStorage.load() + config)
              }
              catch (any) {
                  log.error("Failed to create missing script field configuration for field: '${customField.name}', with id: ${customField.id}", any)
              }
          } else {
              log.warn "Unexpected custom field type: '${customField.name}', with id: ${customField.id}"
          }
      }
      //noinspection GroovyAccessibility
      (scriptFieldManager as ScriptFieldManagerImpl).byFieldConfigSchemeIdCache.removeAll()
      "Done"
      
      

      That should resolve the "Missing parameters for fields" error that is preventing you from creating issues.

      This is a timing issue. CustomFieldManager.getCustomFieldObjects()  filters out custom fields which descriptor can't be found.

      It can happen that during plugin upgrade descriptors for SR custom fields haven't fully initialised at the time AddMissingScriptFieldConfigurationsUpgradeTask is executed.

      Configuration of such customfields isn't checked by upgrade task and can result in "Missing parameters for fields" exception later.

       

        Attachments

          Structure

            Activity

              People

              Assignee:
              szaporozhtsev Sergey Zaporozhtsev [X] (Inactive)
              Reporter:
              szaporozhtsev Sergey Zaporozhtsev [X] (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Structure Helper Panel