Add a FLATTEN_RECORD_LIST formula #1215
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Formulas
Carts.lookupRecords(customer=$id).Cart
returns a "list of lists/RecordSet" ([Foods[[1, 2, 3]], Foods[[1]]]) which is not handled properly by Grist when trying to type it as a Reference List.A fix is to return a flattened list using a list comprehension [el for val in Carts.lookupRecords(customer=$id).Cart for el in val]
Proposed solution
Add a
FLATTEN_RECORD_LIST(RecordSet, dedup=False)
formula that returns a much more manageable list ofRecords
Related issues
Fixes #1130
Has this been tested?
I'm not sure of the best way to test this. Creating a .grist file that verify the formula returns the good result in nbrowser tests or python tests inside the docstring, but how create a proper RecordSet to do unit tests ?
Thanks for your help.