Skip to content

Commit bd924c5

Browse files
authored
Ensure equal/not_equal can accept any arg type (baserow#4164)
* Make equal/not_equal accept any arg type. * Lint fix
1 parent b0bbdbc commit bd924c5

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

backend/src/baserow/core/formula/argument_types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,11 @@ def test(self, value):
105105

106106
def parse(self, value):
107107
return ensure_string(value)
108+
109+
110+
class AnyBaserowRuntimeFormulaArgumentType(BaserowRuntimeFormulaArgumentType):
111+
def test(self, value):
112+
return True
113+
114+
def parse(self, value):
115+
return value

backend/src/baserow/core/formula/runtime_formula_types.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from baserow.core.formula.argument_types import (
1111
AddableBaserowRuntimeFormulaArgumentType,
12+
AnyBaserowRuntimeFormulaArgumentType,
1213
BooleanBaserowRuntimeFormulaArgumentType,
1314
DateTimeBaserowRuntimeFormulaArgumentType,
1415
DictBaserowRuntimeFormulaArgumentType,
@@ -113,8 +114,8 @@ def execute(self, context: FormulaContext, args: FormulaArgs):
113114
class RuntimeEqual(RuntimeFormulaFunction):
114115
type = "equal"
115116
args = [
116-
NumberBaserowRuntimeFormulaArgumentType(),
117-
NumberBaserowRuntimeFormulaArgumentType(),
117+
AnyBaserowRuntimeFormulaArgumentType(),
118+
AnyBaserowRuntimeFormulaArgumentType(),
118119
]
119120

120121
def validate_number_of_args(self, args):
@@ -127,8 +128,8 @@ def execute(self, context: FormulaContext, args: FormulaArgs):
127128
class RuntimeNotEqual(RuntimeFormulaFunction):
128129
type = "not_equal"
129130
args = [
130-
NumberBaserowRuntimeFormulaArgumentType(),
131-
NumberBaserowRuntimeFormulaArgumentType(),
131+
AnyBaserowRuntimeFormulaArgumentType(),
132+
AnyBaserowRuntimeFormulaArgumentType(),
132133
]
133134

134135
def validate_number_of_args(self, args):

web-frontend/modules/core/runtimeFormulaArgumentTypes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,13 @@ export class TimezoneBaserowRuntimeFormulaArgumentType extends BaserowRuntimeFor
121121
return ensureString(value)
122122
}
123123
}
124+
125+
export class AnyBaserowRuntimeFormulaArgumentType extends BaserowRuntimeFormulaArgumentType {
126+
test(value) {
127+
return true
128+
}
129+
130+
parse(value) {
131+
return value
132+
}
133+
}

web-frontend/modules/core/runtimeFormulaTypes.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ObjectBaserowRuntimeFormulaArgumentType,
77
BooleanBaserowRuntimeFormulaArgumentType,
88
TimezoneBaserowRuntimeFormulaArgumentType,
9+
AnyBaserowRuntimeFormulaArgumentType,
910
} from '@baserow/modules/core/runtimeFormulaArgumentTypes'
1011
import {
1112
InvalidFormulaArgumentType,
@@ -487,8 +488,8 @@ export class RuntimeEqual extends RuntimeFormulaFunction {
487488

488489
get args() {
489490
return [
490-
new NumberBaserowRuntimeFormulaArgumentType(),
491-
new NumberBaserowRuntimeFormulaArgumentType(),
491+
new AnyBaserowRuntimeFormulaArgumentType(),
492+
new AnyBaserowRuntimeFormulaArgumentType(),
492493
]
493494
}
494495

@@ -502,7 +503,7 @@ export class RuntimeEqual extends RuntimeFormulaFunction {
502503
}
503504

504505
getExamples() {
505-
return ['2 = 3 = false']
506+
return ['2 = 3 = false', '"foo" = "bar" = false', '"foo" = "foo" = true']
506507
}
507508
}
508509

@@ -525,8 +526,8 @@ export class RuntimeNotEqual extends RuntimeFormulaFunction {
525526

526527
get args() {
527528
return [
528-
new NumberBaserowRuntimeFormulaArgumentType(),
529-
new NumberBaserowRuntimeFormulaArgumentType(),
529+
new AnyBaserowRuntimeFormulaArgumentType(),
530+
new AnyBaserowRuntimeFormulaArgumentType(),
530531
]
531532
}
532533

@@ -540,7 +541,7 @@ export class RuntimeNotEqual extends RuntimeFormulaFunction {
540541
}
541542

542543
getExamples() {
543-
return ['2 != 3 = true']
544+
return ['2 != 3 = true', '"foo" != "foo" = false', '"foo" != "bar" = true']
544545
}
545546
}
546547

0 commit comments

Comments
 (0)