Azure / logicapps

Azure Logic Apps labs, samples, and tools
MIT License
367 stars 302 forks source link

Until loop checks for variable to be true to break off, but breaks off before that variable is set to true #1226

Open ivanderwolf opened 2 weeks ago

ivanderwolf commented 2 weeks ago

Describe the Bug with repro steps

  1. In a logic app include an until statement
  2. Within it, get paginated results from an API until you reach last page
  3. Have a condition check if there are more results to be got, if yes, keep looping, if no, set var "done" to true
  4. The loop is stopped if var "done" is true

This particular set-up will sometimes loop until it is actually done, and sometimes will stop just 1 loop short of the expected amount of loops. If you check the last run it does not set the variable to true, but somehow still stops running.

Image

What type of Logic App Is this happening in?

Standard (Portal)

Which operating system are you using?

Windows

Are you using new designer or old designer

New Designer

Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

No

Workflow JSON

{
  "definition": {
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
    "actions": {
      "Initialize_currentContact": {
        "type": "InitializeVariable",
        "inputs": {
          "variables": [
            {
              "name": "currentContact",
              "type": "object"
            }
          ]
        },
        "runAfter": {
          "Initialize_firstresult": [
            "Succeeded"
          ]
        }
      },
      "Initialize_done": {
        "type": "InitializeVariable",
        "inputs": {
          "variables": [
            {
              "name": "done",
              "type": "boolean",
              "value": false
            }
          ]
        },
        "runAfter": {}
      },
      "Initialize_firstresult": {
        "type": "InitializeVariable",
        "inputs": {
          "variables": [
            {
              "name": "firstresult",
              "type": "integer",
              "value": 0
            }
          ]
        },
        "runAfter": {
          "Initialize_done": [
            "Succeeded"
          ]
        }
      },
      "Until_done_is_true": {
        "type": "Until",
        "expression": "@equals(variables('done'), true)",
        "limit": {
          "count": 60,
          "timeout": "PT5M"
        },
        "actions": {
          "Are_more_contacts_available": {
            "type": "If",
            "expression": {
              "and": [
                {
                  "equals": [
                    "@body('Parse_contacts')[0]['result']['more_items_in_collection']",
                    true
                  ]
                }
              ]
            },
            "actions": {
              "Set_firstresult_to_nextstart": {
                "type": "SetVariable",
                "inputs": {
                  "name": "firstresult",
                  "value": "@body('Parse_contacts')[0]['result']['next_start']"
                }
              }
            },
            "else": {
              "actions": {
                "Set_done_to_true": {
                  "type": "SetVariable",
                  "inputs": {
                    "name": "done",
                    "value": true
                  }
                }
              }
            },
            "runAfter": {
              "For_each_contact": [
                "Succeeded"
              ]
            }
          },
          "For_each_contact": {
            "type": "Foreach",
            "foreach": "@body('Parse_contacts')[0]['result']['rows']",
            "actions": {
              "Insert_or_Update_Contact": {
                "type": "ServiceProvider",
                "inputs": {
                  "parameters": {
                    "tableName": "cacheContact",
                    "entity": {
                      "PartitionKey": "@{variables('currentContact')['id']}",
                      "RowKey": "@{variables('currentContact')['id']}",
                      "email": "@{variables('currentContact')['email']}",
                      "firstname": "@{variables('currentContact')['firstname']}",
                      "id": "@variables('currentContact')['id']",
                      "infix": "@{variables('currentContact')['infix']}",
                      "lastname": "@{variables('currentContact')['lastname']}",
                      "uuid": "@{if(contains(variables('currentContact'),'customfield_uuid'), variables('currentContact')['customfield_uuid'], '')}",
                      "companyid": "@{variables('currentContact')['company']?['id']}"
                    }
                  },
                  "serviceProviderConfiguration": {
                    "connectionName": "azureTables-4",
                    "operationId": "upsertEntity",
                    "serviceProviderId": "/serviceProviders/azureTables"
                  }
                },
                "runAfter": {
                  "Set_currentContact": [
                    "Succeeded"
                  ]
                }
              },
              "Set_currentContact": {
                "type": "SetVariable",
                "inputs": {
                  "name": "currentContact",
                  "value": "@items('For_each_contact')"
                }
              }
            },
            "runAfter": {
              "Parse_contacts": [
                "Succeeded"
              ]
            },
            "runtimeConfiguration": {
              "concurrency": {
                "repetitions": 1
              }
            }
          },
          "HTTP_-*Get_contacts": {
            "type": "Http",
            "inputs": {
              "uri": "@{parameters('GrippBaseUrl')}/contacts/fetch?firstResult=@{variables('firstresult')}",
              "method": "POST",
              "headers": {
                "Ocp-Apim-Subscription-Key": "@parameters('ApimSubscriptionKey')"
              }
            }
          },
          "Parse_contacts": {
            "type": "ParseJson",
            "inputs": {
              "content": "@body('HTTP*-*Get_contacts')",
              "schema": {
                "$schema": "http://json-schema.org/draft-04/schema#",
                "items": [
                  {
                    "properties": {
                      "error": {
                        "type": [
                          "null",
                          "string"
                        ]
                      },
                      "id": {
                        "type": "integer"
                      },
                      "result": {
                        "properties": {
                          "count": {
                            "type": "integer"
                          },
                          "limit": {
                            "type": "integer"
                          },
                          "more_items_in_collection": {
                            "type": "boolean"
                          },
                          "next_start": {
                            "type": "integer"
                          },
                          "rows": {
                            "items": [
                              {
                                "properties": {
                                  "active": {
                                    "type": "boolean"
                                  },
                                  "company": {
                                    "properties": {
                                      "discr": {
                                        "type": "string"
                                      },
                                      "id": {
                                        "type": "integer"
                                      },
                                      "searchname": {
                                        "type": "string"
                                      }
                                    },
                                    "type": "object"
                                  },
                                  "createdon": {
                                    "properties": {
                                      "date": {
                                        "type": "string"
                                      },
                                      "timezone": {
                                        "type": "string"
                                      },
                                      "timezone_type": {
                                        "type": "integer"
                                      }
                                    },
                                    "type": "object"
                                  },
                                  "customfield_uuid": {
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  },
                                  "dateofbirth": {
                                    "type": [
                                      "string",
                                      "object",
                                      "null"
                                    ]
                                  },
                                  "department": {
                                    "type": "string"
                                  },
                                  "discr": {
                                    "type": "string"
                                  },
                                  "email": {
                                    "type": "string"
                                  },
                                  "extendedproperties": {
                                    "type": [
                                      "string",
                                      "object",
                                      "null"
                                    ]
                                  },
                                  "firstname": {
                                    "type": "string"
                                  },
                                  "function": {
                                    "type": "string"
                                  },
                                  "id": {
                                    "type": "integer"
                                  },
                                  "infix": {
                                    "type": "string"
                                  },
                                  "initials": {
                                    "type": "string"
                                  },
                                  "lastname": {
                                    "type": "string"
                                  },
                                  "mobile": {
                                    "type": "string"
                                  },
                                  "notes": {
                                    "type": "string"
                                  },
                                  "phone": {
                                    "type": "string"
                                  },
                                  "salutation": {
                                    "properties": {
                                      "id": {
                                        "type": "integer"
                                      },
                                      "searchname": {
                                        "type": "string"
                                      }
                                    },
                                    "type": [
                                      "object",
                                      "null"
                                    ]
                                  },
                                  "searchname": {
                                    "type": "string"
                                  },
                                  "showoncompanycard": {
                                    "type": "boolean"
                                  },
                                  "tags": {
                                    "items": {},
                                    "type": "array"
                                  },
                                  "title": {
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  },
                                  "updatedon": {
                                    "type": [
                                      "string",
                                      "null",
                                      "object"
                                    ]
                                  }
                                },
                                "type": "object"
                              }
                            ],
                            "type": "array"
                          },
                          "start": {
                            "type": "integer"
                          }
                        },
                        "type": "object"
                      }
                    },
                    "type": "object"
                  }
                ],
                "type": "array"
              }
            },
            "runAfter": {
              "HTTP*-_Get_contacts": [
                "Succeeded"
              ]
            }
          }
        },
        "runAfter": {
          "Initialize_currentContact": [
            "Succeeded"
          ]
        }
      }
    },
    "contentVersion": "1.0.0.0",
    "outputs": {},
    "triggers": {
      "Recurrence": {
        "type": "Recurrence",
        "recurrence": {
          "frequency": "Day",
          "interval": 1,
          "schedule": {
            "hours": [
              "1"
            ],
            "minutes": [
              15
            ]
          },
          "timeZone": "W. Europe Standard Time"
        }
      }
    }
  },
  "kind": "Stateful"
}

Screenshots or Videos

No response

Browser

Chrome

Additional context

No response

Eric-B-Wu commented 1 week ago

transferring runtime issue to backend