Inedo Community Forums Forums
    • Recent
    • Tags
    • Popular
    • Login

    Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

    If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

    HTTP/500 error when re-running a job from History which has a blank/empty template variables

    Scheduled Pinned Locked Moved Support
    otter
    6 Posts 3 Posters 20 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      jimbobmcgee
      last edited by jimbobmcgee

      I have an Otter job template for which I have defined a number of custom variables, some of which are marked as Required and some are not.

      If I view previous executions of that job in /jobs/history, there is a small ▶ (play) button icon against each execution, for which I believe the intention is to re-run any one particular execution with the variable prompts pre-populated with the previously-entered values for that execution.

      If there were no custom variables defined on the template or, for that execution, if all the custom variables were populated with a value, clicking that button works as intended.

      If, however, I did not set a value for one of the properties (i.e. it was left as an empty text box), clicking that button results in an HTTP/500 server error. The Diagnostic Centre page yields the following:

      An error occurred in the web application: The given key 'MyCustomVariableName' was not present in the dictionary.
      
      URL: http://xxxx:8626/jobs/from-template?jobTemplateId=Default%3A%3AJobTemplate%3A%3AMyTemplateFolder%2FMyTemplateName&jobId=140
      Referrer: http://xxxx:8626/jobs/history
      User: Admin
      User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0
      Stack trace:    at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
         at Inedo.Otter.WebApplication.Pages.Jobs.CreateJobFromTemplatePage.VariablePrompts..ctor(IEnumerable`1 variables, Dictionary`2 selectedValues, VariableTemplateContext context)
         at Inedo.Otter.WebApplication.Pages.Jobs.CreateJobFromTemplatePage.CreateChildControls()
         at Inedo.Otter.WebApplication.Pages.OtterSimplePageBase.InitializeAsync()
         at Inedo.Web.PageFree.SimplePageBase.ExecutePageLifeCycleAsync()
         at Inedo.Web.PageFree.SimplePageBase.ProcessRequestAsync(AhHttpContext context)
         at Inedo.Web.AhWebMiddleware.InvokeAsync(HttpContext context)
      
      ::HTTP Error on 19/12/2024 18:55:42::
      

      I'm fairly certain it boils down to a simple null-ref check in the CreateJobFromTemplatePage class (decompiled from Otter.WebApplication.dll):

      public VariablePrompts(IEnumerable<TemplateVariable> variables, Dictionary<string, string> selectedValues, VariableTemplateContext context)
      {
          object item;
          CreateJobFromTemplatePage.VariablePrompts variablePrompt = this;
          foreach (TemplateVariable variable in variables)
          {
              if (this.variableValues.ContainsKey(variable.Name))
              {
                  continue;
              }
              TemplateVariable templateVariable = variable;
              if (selectedValues != null)
              {
                  item = selectedValues[variable.Name];    // <-- here
              }
              else
              {
                  item = null;
              }
              if (item == null)
              {
                  item = variable.InitialValue;
              }
              templateVariable.InitialValue = (string)item;
              VariableTemplateInput variableTemplateInput = variable.Type.CreateInput(variable, context);
              variablePrompt.get_Controls().Add(variableTemplateInput);
              this.variableValues.Add(variable.Name, variableTemplateInput);
          }
      }
      

      My guess is that you are not serializing unset/empty values or that they are not being deserialized correctly to the selectedValues dictionary by the caller. Whether or not that is a larger problem is unknown, but you can probably bandage it here by simply changing to...

      if (selectedValues != null || !selectedValues.ContainsKey(variable.Name))
      {
          item = selectedValues[variable.Name];
      }
      

      ...without affecting the surrounding logic.

      dean-houstonD 1 Reply Last reply Reply Quote 0
      • dean-houstonD Offline
        dean-houston inedo-engineer @jimbobmcgee
        last edited by

        @jimbobmcgee thanks for the detailed analysis! This is on my list, but haven't had time to properly reproduce and test this.... but as you noted, the code fix looks so easy.

        I just made a quick change (OT-513) and prerelease (2024.2-rc.1). Can you give it a shot?

        https://docs.inedo.com/docs/installation/windows/howto-install-prerelease-product-versions

        J 1 Reply Last reply Reply Quote 0
        • J Offline
          jimbobmcgee @dean-houston
          last edited by

          @dean-houston This might be a really silly question, but what is the URL for the Pre-Release package source feed?

          The linked documentation suggests that Package source should be a drop-down list in InedoHub (from which I should select Inedo's Prerelease Feed); mine is a free text field containing https://proget.inedo.com/upack/Products.

          atrippA 1 Reply Last reply Reply Quote 0
          • atrippA Offline
            atripp inedo-engineer @jimbobmcgee
            last edited by

            @jimbobmcgee

            I think you might have an old version of Inedo Hub; you can just download a new version and the dropdown will be there. I guess the old version should work, I just worry about some bugfix/change that might cause newer versions to not work.

            The feed is https://proget.inedo.com/upack/PrereleaseProducts

            1 Reply Last reply Reply Quote 0
            • J Offline
              jimbobmcgee
              last edited by jimbobmcgee

              Can confirm 2024.2-rc.1 fixes this specific HTTP/500 error. Thanks for looking.

              (@atripp - as soon as I manually changed the feed URL in InedoHub to the one you gave, it offered to update itself from 1.3.12 to 1.4.4, so I did that first. Ironically, 1.3.12 is the version in the documentation page's screenshot, so I didn't consider it might be out of date.)

              atrippA 1 Reply Last reply Reply Quote 0
              • atrippA Offline
                atripp inedo-engineer @jimbobmcgee
                last edited by

                @jimbobmcgee excellent thanks!! Release has been published then :)

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • 1 / 1
                • First post
                  Last post
                Inedo Website Home • Support Home • Code of Conduct • Forums Guide • Documentation