mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-11 07:51:20 +00:00
Merge branch '1880-fix-when_empty-must-be-the-same-type-error-when-working-with-url-and-email-fields-2' into 'develop'
Resolve "Fix when_empty must be the same type error when working with url and email fields" Closes #1880 See merge request baserow/baserow!1682
This commit is contained in:
commit
b531ed4659
4 changed files with 51 additions and 2 deletions
backend
src/baserow/contrib/database/formula
tests/baserow/contrib/database/formula
changelog/entries/unreleased/bug
|
@ -127,6 +127,7 @@ def register_formula_functions(registry):
|
|||
registry.register(BaserowLower())
|
||||
registry.register(BaserowConcat())
|
||||
registry.register(BaserowToText())
|
||||
registry.register(BaserowToVarchar())
|
||||
registry.register(BaserowT())
|
||||
registry.register(BaserowReplace())
|
||||
registry.register(BaserowSearch())
|
||||
|
@ -378,6 +379,30 @@ class BaserowToText(OneArgumentBaserowFunction):
|
|||
)
|
||||
|
||||
|
||||
class BaserowToVarchar(OneArgumentBaserowFunction):
|
||||
"""
|
||||
Internal function not registered in the frontend intentionally as we don't want
|
||||
users making char types. Used purely for working with our BaserowFormulaCharType
|
||||
on internal operations.
|
||||
"""
|
||||
|
||||
type = "tovarchar"
|
||||
arg_type = [BaserowFormulaTextType]
|
||||
try_coerce_nullable_args_to_not_null = False
|
||||
|
||||
def type_function(
|
||||
self,
|
||||
func_call: BaserowFunctionCall[UnTyped],
|
||||
arg: BaserowExpression[BaserowFormulaValidType],
|
||||
) -> BaserowExpression[BaserowFormulaType]:
|
||||
return arg.with_valid_type(
|
||||
BaserowFormulaCharType(nullable=arg.expression_type.nullable)
|
||||
)
|
||||
|
||||
def to_django_expression(self, arg: Expression) -> Expression:
|
||||
return Cast(arg, output_field=fields.CharField())
|
||||
|
||||
|
||||
class BaserowT(OneArgumentBaserowFunction):
|
||||
type = "t"
|
||||
arg_type = [BaserowFormulaValidType]
|
||||
|
|
|
@ -106,7 +106,7 @@ class BaserowFormulaTextType(
|
|||
)
|
||||
|
||||
|
||||
class BaserowFormulaCharType(BaserowFormulaBaseTextType, BaserowFormulaValidType):
|
||||
class BaserowFormulaCharType(BaserowFormulaTextType, BaserowFormulaValidType):
|
||||
type = "char"
|
||||
baserow_field_type = "text"
|
||||
can_order_by_in_array = True
|
||||
|
@ -116,8 +116,13 @@ class BaserowFormulaCharType(BaserowFormulaBaseTextType, BaserowFormulaValidType
|
|||
field_name, "value", "text", output_field=models.TextField()
|
||||
)
|
||||
|
||||
def placeholder_empty_baserow_expression(
|
||||
self,
|
||||
) -> "BaserowExpression[BaserowFormulaValidType]":
|
||||
return formula_function_registry.get("tovarchar")(literal(""))
|
||||
|
||||
class BaserowFormulaLinkType(BaserowFormulaTextType):
|
||||
|
||||
class BaserowFormulaLinkType(BaserowFormulaValidType):
|
||||
type = "link"
|
||||
baserow_field_type = None
|
||||
can_order_by = False
|
||||
|
|
|
@ -354,6 +354,7 @@ VALID_FORMULA_TESTS = [
|
|||
("get_link_url(link('https://www.google.com'))", "https://www.google.com"),
|
||||
("get_link_label(button('1', 'l'))", "l"),
|
||||
("get_link_url(button('a' + 'b', 'l' + 'a'))", "ab"),
|
||||
("lower(tovarchar('AB'))", "ab"),
|
||||
(
|
||||
"encode_uri('http://example.com/wiki/Señor')",
|
||||
"http://example.com/wiki/Se%c3%b1or",
|
||||
|
@ -487,6 +488,17 @@ def test_can_compare_a_datetime_field_and_text_with_eu_formatting(data_fixture):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_can_upper_an_email_field(data_fixture):
|
||||
assert_formula_results_are_case(
|
||||
data_fixture,
|
||||
given_field_in_table=data_fixture.create_email_field(name="email"),
|
||||
given_field_has_rows=["test@test.com", "other@das.c", None],
|
||||
when_created_formula_is="upper(field('email'))",
|
||||
then_formula_values_are=["TEST@TEST.COM", "OTHER@DAS.C", ""],
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_todate_handles_empty_values(data_fixture):
|
||||
assert_formula_results_are_case(
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"type": "bug",
|
||||
"message": "fix when_empty must be the same type error when working with url and email fields",
|
||||
"issue_number": 1880,
|
||||
"bullet_points": [],
|
||||
"created_at": "2023-09-19"
|
||||
}
|
Loading…
Add table
Reference in a new issue