diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e5f62c6fad..33233cc041 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -48,6 +48,7 @@ Changelog * Fix: Use the correct padding for autocomplete block picker (Umar Farouk Yunusa) * Fix: Ensure that short content pages (such as editing snippets) do not show an inconsistent background (Sage Abdullah) * Fix: Fix horizontal positioning of rich text inline toolbar (Thibaud Colas) + * Fix: Ensure that `DecimalBlock` correctly handles `None`, when `required=False`, values (Natarajan Balaji) * Docs: Add custom permissions section to permissions documentation page (Dan Hayden) * Docs: Add documentation for how to get started with contributing translations for the Wagtail admin (Ogunbanjo Oluwadamilare) * Docs: Officially recommend `fnm` over `nvm` in development documentation (LB (Ben) Johnston) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index fb4f872c3f..a2f43f5523 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -675,6 +675,7 @@ Contributors * Jeremy Thompson * Ben Gosney * damascene +* Natarajan Balaji Translators =========== diff --git a/docs/releases/4.2.md b/docs/releases/4.2.md index 2a41fb9010..d0f58fe9b7 100644 --- a/docs/releases/4.2.md +++ b/docs/releases/4.2.md @@ -62,6 +62,7 @@ Wagtail now provides a set of utilities for creating data migrations on StreamFi * Use the correct padding for autocomplete block picker (Umar Farouk Yunusa) * Ensure that short content pages (such as editing snippets) do not show an inconsistent background (Sage Abdullah) * Fix horizontal positioning of rich text inline toolbar (Thibaud Colas) + * Ensure that `DecimalBlock` correctly handles `None`, when `required=False`, values (Natarajan Balaji) ### Documentation diff --git a/wagtail/blocks/field_block.py b/wagtail/blocks/field_block.py index 224cc556a6..827d78bd45 100644 --- a/wagtail/blocks/field_block.py +++ b/wagtail/blocks/field_block.py @@ -251,7 +251,10 @@ class DecimalBlock(FieldBlock): super().__init__(*args, **kwargs) def to_python(self, value): - return Decimal(value) + if value is None: + return value + else: + return Decimal(value) class Meta: icon = "plus-inverse" diff --git a/wagtail/tests/test_blocks.py b/wagtail/tests/test_blocks.py index 507c756180..faa1e9f551 100644 --- a/wagtail/tests/test_blocks.py +++ b/wagtail/tests/test_blocks.py @@ -419,6 +419,11 @@ class TestDecimalBlock(TestCase): ) # decimals get saved as string in JSON field self.assertEqual(type(block_val), Decimal) + def test_type_to_python_decimal_none_value(self): + block = blocks.DecimalBlock() + block_val = block.to_python(None) + self.assertIsNone(block_val) + def test_render(self): block = blocks.DecimalBlock() test_val = Decimal(1.63)