Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] evaluation: evaluateFormula no longer throws #3371

Closed
wants to merge 1 commit into from

Conversation

rrahir
Copy link
Collaborator

@rrahir rrahir commented Jan 2, 2024

The getter evaluateFormula required to be wrapped in a try/catch statement to handle the evaluation errors but as this is quite error prone, we decided to change it to no longer throw. The getter will instead the value of the error that was previously thrown.

Task: 3576149

Description:

description of this task, what is implemented and why it is implemented that way.

Task: : TASK_ID

review checklist

  • feature is organized in plugin, or UI components
  • support of duplicate sheet (deep copy)
  • in model/core: ranges are Range object, and can be adapted (adaptRanges)
  • in model/UI: ranges are strings (to show the user)
  • undo-able commands (uses this.history.update)
  • multiuser-able commands (has inverse commands and transformations where needed)
  • new/updated/removed commands are documented
  • exportable in excel
  • translations (_t("qmsdf %s", abc))
  • unit tested
  • clean commented code
  • track breaking changes
  • doc is rebuild (npm run doc)
  • status is correct in Odoo

@robodoo
Copy link
Collaborator

robodoo commented Jan 2, 2024

Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good 👍
Only 2 small questions

@@ -188,7 +184,7 @@ export class EvaluationConditionalFormatPlugin extends UIPlugin {
return percentile(rangeValues, Number(threshold.value) / 100, true);
case "formula":
const value = threshold.value && this.getters.evaluateFormula(threshold.value);
return !(value instanceof Promise) ? value : null;
return typeof value == "number" ? value : null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a behavior change, right ?
Technically, value could be a string before (even if it should not according to the method return type).
Are we missing a test where the formula evaluates to a string ?

@@ -380,7 +376,7 @@ export class EvaluationConditionalFormatPlugin extends UIPlugin {
if (cell && cell.evaluated.type === CellValueType.error) {
return false;
}
const values = rule.values.map(parsePrimitiveContent);
const values = rule.values?.map(parsePrimitiveContent) || [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary ? The type definition states that values is always defined. But maybe it's lying :p

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the data fed to Model unfortunately bypasses it :/. I feel like TS could warn me that the chaining ?. is unnecessary since values is always defined 🤔

@rrahir rrahir force-pushed the 16.0-evaluateFormula-no-throw-rar branch from 810d949 to ea6cd26 Compare January 4, 2024 08:12
The getter `evaluateFormula` required to be wrapped in a try/catch
statement to handle the evaluation errors but as this is quite error
prone, we decided to change it to no longer throw. The getter will
instead the value of the error that was previously thrown.

Task: 3576149
@rrahir rrahir force-pushed the 16.0-evaluateFormula-no-throw-rar branch from ea6cd26 to 5627f50 Compare January 4, 2024 08:50
Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

robodoo r+

robodoo pushed a commit that referenced this pull request Jan 4, 2024
The getter `evaluateFormula` required to be wrapped in a try/catch
statement to handle the evaluation errors but as this is quite error
prone, we decided to change it to no longer throw. The getter will
instead the value of the error that was previously thrown.

closes #3371

Task: 3576149
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
@robodoo robodoo closed this Jan 4, 2024
@fw-bot fw-bot deleted the 16.0-evaluateFormula-no-throw-rar branch January 18, 2024 09:46
rrahir added a commit that referenced this pull request Aug 1, 2024
The getter `getPivotCellFromPosition` parses pivot cells domain args
but this step assumes that the domain is valid (e.g. refers to a valid
groupby,measure combination). Unfortunately, if the domain is invalid,
the parsing will crash.

Similarly to the decision made for the getter `evaluateFormula`[^1]
we wrap the parsing in a try/catch statement and in case of faulty evaluation,
return the same result as for invalid/non-existing pivots, that is an
empty Pivotcell.

[^1]: See #3371

Task: 4088765
robodoo pushed a commit that referenced this pull request Aug 9, 2024
The getter `getPivotCellFromPosition` parses pivot cells domain args
but this step assumes that the domain is valid (e.g. refers to a valid
groupby,measure combination). Unfortunately, if the domain is invalid,
the parsing will crash.

Similarly to the decision made for the getter `evaluateFormula`[^1]
we wrap the parsing in a try/catch statement and in case of faulty evaluation,
return the same result as for invalid/non-existing pivots, that is an
empty Pivotcell.

[^1]: See #3371

closes #4741

Task: 4088765
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
fw-bot pushed a commit that referenced this pull request Aug 9, 2024
The getter `getPivotCellFromPosition` parses pivot cells domain args
but this step assumes that the domain is valid (e.g. refers to a valid
groupby,measure combination). Unfortunately, if the domain is invalid,
the parsing will crash.

Similarly to the decision made for the getter `evaluateFormula`[^1]
we wrap the parsing in a try/catch statement and in case of faulty evaluation,
return the same result as for invalid/non-existing pivots, that is an
empty Pivotcell.

[^1]: See #3371

Task: 4088765
X-original-commit: 693db2b
rrahir added a commit that referenced this pull request Aug 9, 2024
The getter `getPivotCellFromPosition` parses pivot cells domain args
but this step assumes that the domain is valid (e.g. refers to a valid
groupby,measure combination). Unfortunately, if the domain is invalid,
the parsing will crash.

Similarly to the decision made for the getter `evaluateFormula`[^1]
we wrap the parsing in a try/catch statement and in case of faulty evaluation,
return the same result as for invalid/non-existing pivots, that is an
empty Pivotcell.

[^1]: See #3371

Task: 4088765
X-original-commit: 693db2b
robodoo pushed a commit that referenced this pull request Aug 9, 2024
The getter `getPivotCellFromPosition` parses pivot cells domain args
but this step assumes that the domain is valid (e.g. refers to a valid
groupby,measure combination). Unfortunately, if the domain is invalid,
the parsing will crash.

Similarly to the decision made for the getter `evaluateFormula`[^1]
we wrap the parsing in a try/catch statement and in case of faulty evaluation,
return the same result as for invalid/non-existing pivots, that is an
empty Pivotcell.

[^1]: See #3371

closes #4805

Task: 4088765
X-original-commit: 693db2b
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Rémi Rahir (rar) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants