mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-16 19:30:13 -04:00
This was causing some tests for the "estimate_volume" endpoint to fail due to the surprising way that form handles "''": - The form is the exclusive user of the ForgivingIntegerField [^1]. - The field secretly/silently converts "''" to the integer 0 [^2]. If the validations fail, we don't want to surprise the user with a "0" when they didn't enter one. The field already handles this by massaging the values in the __call__ method that generates the HTML for the form [^3]. However, there are two scenarios: - User submits field with '' - converted to integer 0. - User submits field with '0' - remains as a string. In the case where "value" is "''", the parent class will use the converted value from form.data instead [^4]. This seems to be an oversight and so we get either the integer 0 (from form.data) or the string '0' (from the value kwarg). Complicado! Previously it was a fluke that we avoided replaying the integer 0 to the user; the previous commit removes the fluke. This fixes the conditional to always use the data in the "value" kwarg if it has been provided, as it's meant to override "form.data". [^1]:9f63449384[^2]:a22b8cf684/app/main/forms.py (L364)[^3]:a22b8cf684/app/main/forms.py (L393)[^4]:a22b8cf684 (diff-a1c8d24b22d4478fe71f75fd43b71b18dd82aae97bc63de84473a6da1902909bR215)