51
Views
10
Comments
[OS Bug] Be ware of passing List to an action in the same module
Discussion

Hi, i found a bug in Outsystems

1. in the program there is a variable local of type List

2. The list elements are then populated.... using equation like

List.,,,,.current.attr = 'bugs'

...

3. then the List is passed to other action, say it action B

4. In the B, the element's value exists ('bugs'..etc)

5. What amazing is that the property Empty of the List is still TRUE

To workaround, use appendList and create another local variable of the element's type.

may this helps, thanks


2021-09-06 15-09-53
Dorine Boudry
 
MVP

can you give more details, like what type of application, what type of actions (server ? client ? screen ?)


EDIT : Ok, just did a quick test, and can see same thing, I think i would expect it to still be empty, but it is confusing that it has value.  

ALSO : it has nothing to do with passing to other action, anytime you assign an element value of an empty list, the list is still empty.

2025-01-09 14-56-57
IQ78

Yes, it will be a logic error as in the Action B there is a check like this 

if Data_Pallete.Empty ...blabla...


It is a server  action called another server action

thanks


2019-09-30 07-35-56
Aurelio Junior

I don't think this is a bug. If you don't append anything to an empty list, I think it makes sense for "Empty" to be True. If you're going to use the list in some logic, either to assign values to it or to read its values, you should always start with checking the Empty property.

2021-09-06 15-09-53
Dorine Boudry
 
MVP

yes, agree the Empty being True is correct, but it is confusing that you can assign to list.current, and also retrieve value out of list.current, all while it being empty.

For most uses of a list, like iterations, or a table widget, that won't be a problem though, it will simply act like an empty list, even if there are values filled.  

So, as you say, it comes down to coding hygiene of checking against empty before doing something with current.

2025-01-09 14-56-57
IQ78

Hi, i think the spirit of OS is to enable citizen developer to do programming safely.

If the list element can be assigned, but it is considered empty, it is not a good reasoning, prone to logic error.

thanks

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Correct, but this is only one of multiple examples where you can make not working code that OutSystems doesn't detect. Another example is using an expression with = on the right part of the Assign widget. OutSystems will not detect this as an error, typical beginner mistakes. You can even make action flows that are syntaxwise not correct that OutSystems will not detect. These things you see also in other programming languages, syntax wise they are correct, but the result of what you code is wrong because you do something that wasn't intended.

For example this is not detected as an issue, but makes not sense either:

Or an action flow with just this, is also not detected as an issue.

2018-11-30 08-20-55
Hendra

Hi ibox,

I don't think this is a bug, as if you use a local variable (list type) then 'assign' it other list type local variable, whatever happens in first variable will also applied to second variable.

To achieve another result (only get all records at that moment only) use 'List append all' to another variable. This approach will send all records to other variable at current state, and will not change eventhough the first variable changed.  

2025-01-09 14-56-57
IQ78

Hi Sir,

here is the osp and a snapshot of my use case:

thanks and regards

OS - middle way: "Space cannot be empty, but can be checked empty" ..JK

ListMe.oap
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Ok, there seems to be a lot of confusion here, and I agree that on the surface it looks weird, and yes, the documentation should probably be a bit clearer on this point. However, this is what it is:

  • A List always has a Current available. Yes, even if the List is empty. In that case, Current does not point to an element in the List, as the List is empty;
  • Assigning Current in case the List is empty does not automagically create an element in the List. The only way to add elements to a List are ListAppend and ListAppendAll.

This is not a bug, and it has always been the case (15+ years). It's just one of these things you need to remember when working with OutSystems. Also, one very, very important addition to the above:

  • Never use ListAppend with the Current of the List itself. This will lead to unintended and unpredictable behaviour (at least in server-side actions, I haven't checked for client-side). If you need to assign some values, then append to the list, you have two options:
    • Create a local variable of a single record, assign that, and ListAppend it, or;
    • Use the mapping feature and directly assign the attributes in the ListAppend Element input parameter.

Also, be aware that there are only five cases when Current is guaranteed to point to a specific, predictable record:

  • Directly after an Aggregate or SQL, the output list of that query has its Current set to the first record;
  • Inside a For Each, the Current of the List that's looped over has the value of the element  with index CurrentRowNumber of that List (so that MyList[MyList.CurrentRowNumber] is the same as MyList.Current);
  • After a For Each, the Current of the List that was looped over is set to the last record of the List;
  • In a Table or Table Records, the Current of the List associated with it is the record associated with a particular row;
  • In a Screen Action that is triggered by clicking on a row in a Table or Table Records, the Current of the Table's List is the record associated with the row that was clicked.

In all other cases, do not rely on Current pointing to a specific element, as it is not guaranteed to be predictable. This is particularly true after using a List action (ListAppend, ListInsert, ListIndexOf etc.), do not write code that depends on Current being a specific record (even if, e.g., after a ListInsert it seems to always be the record inserted, etc.), as it is not guaranteed to always be the case.

2025-01-09 14-56-57
IQ78

Thanks Sir,

The statement that a list always has a Current variable reminds me to a dummy node in a linked list, and it makes the algorithm much easier to write for all the linked list's operations (insert first, middle, last, delete, etc) .

Regards 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.