I'm using liquid templates in an Azure Standard Logic App. I have a null / empty test at the beginning of the file that is behaving differently (and weirdly) to LiquidJS and online liquid playgrounds that I test.
This is the statement:
{% assign itemExists = content.existing != null and content.existing.UID != null and content.existing.UID != "" -%}
then I use it later to generate some GraphQL:
{% if itemExists -%}
_a0: updateFoo(input: {
UID: "{{ content.existing.UID }}"
{% else -%}
_a0: insertFoo(input: {
{% endif -%}
The problem is that UID is an empty string ""
and yet it's following the first if
path, thereby producing the output:
_a0: updateFoo(input: {
UID: ""
I've verified that the UID is an empty string in the logic app run history.
I wrote a quick Jasmine test using exactly the same liquid file, and the same inputs from the logic app, using LiquidJS, and it works fine.
Is this a bug in DotLiquid used in logic apps? If so, how can I get around it?
It only shows when you assign the test to a variable, and then try and use that variable in an if
test. This:
{% assign test = "asdf" -%}
{% assign isNullOrWhitespace = test == null or test == empty %}
isNullOrWhitespace is: {{ isNullOrWhitespace }}
Produces isNullOrWhitespace is: asdf
instead of the expected isNullOrWhitespace is: false
Bug report here: https://github.com/dotliquid/dotliquid/issues/537
Yes, in Liquid if its even "" a empty string it doesnt consider as null it will consider as not null.
You can use something like below example:
If its not empty:
{% assign test = "Hello Rithwik Bojja" -%}
{% if test != null and test != empty -%}
The string is not empty and not null.
Value:{{test}}
{% else -%}
The string is empty or null.
{% endif -%}
Output:
If its empty:
{% assign test = "" -%}
{% if test != null and test != empty -%}
The string is not empty and not null.
Value:{{test}}
{% else -%}
The string is empty or null.
{% endif -%}
Output:
For understanding you can execute code here
Edit:
{% assign test = "Rithwik Bojja" %}
{% assign isItemExists = test | default: nil | unless: empty %}
{% if isItemExists %}
The string is not empty and not null.
Value: {{ test }}
{% else %}
The string is empty or null.
{% endif %}