Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-21223

Number and Money fields are not set to NULL in the database

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 4.7.26
    • Fix Version/s: None
    • Component/s: Core CiviCRM
    • Labels:
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding
    • Verified?:
      No
    • How it works currently:
      A Number field cannot be set to empty, empty values are saved as zero.
    • How it should work:
      Saving an empty Number Text field should make it NULL.

      Description

      When using the Number or Money data type, fields are never set to  NULL.

      Select and radio Number fields will appear empty but still have "0" in the database. Text fields will display the "0" (as per the database).

      Reproduced on latest CiviCRM using civicrm-buildkit-vagrant:

      1. Create a custom field for contacts using the Number data type and the Text field type.
      2. Create a new contact and leave the field empty.
      3. See that the field was set to "0" instead of NULL.

       Lack of data and "actually zero" can have different meanings.

      Compare with Integer fields, which do get correctly set to NULL in the database:

      mysql> SELECT * FROM civicrm_value_fundraising_4;
      +----+-----------+----------------------------+------------------------------+-------------------------------+-------------------+
      | id | entity_id | text_number_7 | select_number_8 | radio_number_9|  integer_text_okay_10 |
      +----+-----------+----------------------------+------------------------------+-------------------------------+-------------------+
      |  1 |       204 |             0 |               0 |             0 |                  NULL |
      +----+-----------+----------------------------+------------------------------+-------------------------------+-------------------+
      1 row in set (0.00 sec)

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                gboudrias Guillaume Boudrias
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: