Fix issue where Decimal value block null caused an error

- Fixes #9777
- DecimalBlock value when Null forces a conversion to null which crashes the server. Fixed it by returning null when the value is null and decimal when a value is other than null
pull/9787/head
Natarajan Balaji 2022-12-12 09:54:36 +11:00 zatwierdzone przez LB Johnston
rodzic da90061ca8
commit b6f7fbf828
5 zmienionych plików z 12 dodań i 1 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -675,6 +675,7 @@ Contributors
* Jeremy Thompson
* Ben Gosney
* damascene
* Natarajan Balaji
Translators
===========

Wyświetl plik

@ -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

Wyświetl plik

@ -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"

Wyświetl plik

@ -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)