From c2bf1a80c6e48b35dad7cb6d9e63491cd8f6432c Mon Sep 17 00:00:00 2001 From: goerch Date: Fri, 10 Nov 2023 14:15:32 +0100 Subject: [PATCH] One more fix --- flask_appbuilder/forms.py | 6 +++++- tests/test_forms.py | 30 ++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/flask_appbuilder/forms.py b/flask_appbuilder/forms.py index f850f0c0dc..09c701f81a 100644 --- a/flask_appbuilder/forms.py +++ b/flask_appbuilder/forms.py @@ -207,7 +207,11 @@ def __init__( def convert(self): for type_marker, field in self.conversion_table: if getattr(self.datamodel, type_marker)(self.colname): - col_type = self.datamodel.list_columns[self.colname].type + col_type = ( + self.datamodel.list_columns[self.colname].type + if type_marker in ["is_enum", "is_numeric"] + else None + ) return field(self, col_type) log.error("Column %s Type not supported", self.colname) diff --git a/tests/test_forms.py b/tests/test_forms.py index 5ea744e766..1ac7c79e1c 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -84,9 +84,18 @@ def test_model_without_context(self): self.assertTrue(form.field_float.field_class is FloatField) self.assertTrue(form.field_integer.field_class is IntegerField) print(form.field_numeric_scale0.kwargs["places"]) - self.assertTrue(form.field_numeric_scale0.field_class is DecimalField and not form.field_numeric_scale0.kwargs["places"]) - self.assertTrue(form.field_numeric_scale2.field_class is DecimalField and form.field_numeric_scale2.kwargs["places"] == 2) - self.assertTrue(form.field_numeric_scale4.field_class is DecimalField and form.field_numeric_scale4.kwargs["places"] == 4) + self.assertTrue( + form.field_numeric_scale0.field_class is DecimalField + and not form.field_numeric_scale0.kwargs["places"] + ) + self.assertTrue( + form.field_numeric_scale2.field_class is DecimalField + and form.field_numeric_scale2.kwargs["places"] == 2 + ) + self.assertTrue( + form.field_numeric_scale4.field_class is DecimalField + and form.field_numeric_scale4.kwargs["places"] == 4 + ) self.assertTrue(form.field_string.field_class is StringField) self.assertTrue(form.field_text.field_class is TextAreaField) @@ -114,8 +123,17 @@ def test_model_with_context(self): # self.assertTrue(isinstance(form.field_enum, EnumField)) self.assertTrue(isinstance(form.field_float, FloatField)) self.assertTrue(isinstance(form.field_integer, IntegerField)) - self.assertTrue(isinstance(form.field_numeric_scale0, DecimalField) and not form.field_numeric_scale0.places) - self.assertTrue(isinstance(form.field_numeric_scale2, DecimalField) and form.field_numeric_scale2.places == 2) - self.assertTrue(isinstance(form.field_numeric_scale4, DecimalField) and form.field_numeric_scale4.places == 4) + self.assertTrue( + isinstance(form.field_numeric_scale0, DecimalField) + and not form.field_numeric_scale0.places + ) + self.assertTrue( + isinstance(form.field_numeric_scale2, DecimalField) + and form.field_numeric_scale2.places == 2 + ) + self.assertTrue( + isinstance(form.field_numeric_scale4, DecimalField) + and form.field_numeric_scale4.places == 4 + ) self.assertTrue(isinstance(form.field_string, StringField)) self.assertTrue(isinstance(form.field_text, TextAreaField))