Skip to content

Commit

Permalink
RowParser: Revert boolean parsing change for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
geoo89 committed Jul 9, 2024
1 parent 36e391d commit a923059
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/rpft/parsers/common/rowparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ def is_default_value(model_instance, field, field_value):

def str_to_bool(string):
# in this case, the default value takes effect.
if string.lower() == "false" or string == "0":
if string.lower() == "false":
return False
elif string.lower() == "true" or string == "1":
return True
else:
raise RowParserError("Boolean must be true/1 or false/0 " f'but is "{string}"')
return True


def get_field_name(string):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flowparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ def test_basic_if(self):
"row_id,type,from,include_if,message_text\n"
",send_message,,,text1\n"
",send_message,,FALSE,text2\n"
",send_message,,1,text3\n"
",send_message,,something,text3\n"
",send_message,,False,text4\n"
",send_message,,{{1 == 0}},text5\n"
",send_message,,{@1 == 0@},text6\n"
Expand Down
8 changes: 2 additions & 6 deletions tests/test_rowparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def test_convert_false(self):
{"bool_field": " False "},
{"bool_field": "FALSE"},
{"bool_field": "false"},
{"bool_field": "0"},
]
for inp in inputs:
out = self.parser.parse_row(inp)
Expand All @@ -46,17 +45,14 @@ def test_convert_true(self):
{"bool_field": " True "},
{"bool_field": "TRUE"},
{"bool_field": "true"},
{"bool_field": "something"},
{"bool_field": "1"},
{"bool_field": "0"},
]
for inp in inputs:
out = self.parser.parse_row(inp)
self.assertEqual(out, self.trueModel)

def test_convert_invalid(self):
inp = {"bool_field": "something"}
with self.assertRaises(RowParserError):
_ = self.parser.parse_row(inp)

def test_convert_default(self):
inp = {}
out = self.parser.parse_row(inp)
Expand Down

0 comments on commit a923059

Please sign in to comment.