Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #9440 - Forcing default null value for numeric core fields. #9524

Merged
merged 1 commit into from
Oct 30, 2023

Conversation

SinergiaCRM
Copy link
Contributor

Rebased branch to hotfix from #9441

Closes #9440

Description

As described in the issue, non-custom/core non-required numeric fields aren't saving properly a default empty value in newly created modules.

Motivation and Context

(int) and (float) summoning always return 0 if the value is empty. Therefore we add a condition to return "null" if it's empty.

How To Test This

  1. Create a new module in Module Builder
  2. Add an Integer or Decimal field
  3. Add the field to Edit and Detail View
  4. Deploy module
  5. Create a new record to the module, filling only the required name
  6. Check that the numeric field has an empty value

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Final checklist

  • My code follows the code style of this project found here.
  • My change requires a change to the documentation.
  • I have read the How to Contribute guidelines.

@jack7anderson7 jack7anderson7 added Status:Assessed PRs that have been tested and confirmed to resolve an issue by a core team member Branch:Hotfix labels Mar 29, 2022
Copy link
Contributor

@clemente-raposo clemente-raposo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jack7anderson7 jack7anderson7 added the Status: Passed Code Review Mark issue has passed code review reviewed label Mar 31, 2023
@jack7anderson7 jack7anderson7 added the Status: Requires Testing Requires Manual Testing label Sep 21, 2023
Copy link
Contributor

@johnM2401 johnM2401 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each of the four core number-type fields are rending as "null" when saved as empty now.

I have noticed that this same initial issue happens for other field-types too (ie, saving as " ", rather than NULL):
image

However, I assume this is fine as-is. (As the difference between 0 and NULL for numbers is more distinct)

Assuming this is okay, LGTM!

@johnM2401 johnM2401 added Status: Passed Testing and removed Status: Requires Testing Requires Manual Testing labels Oct 13, 2023
@jack7anderson7 jack7anderson7 merged commit c71bb86 into salesagility:hotfix Oct 30, 2023
1 check passed
@gunnicom
Copy link
Contributor

I think I fix this like this since years (I tried to integrate that in the original Sugar years ago)
Does take the "" => NULL into account, too.

diff --git a/include/database/DBManager.php b/include/database/DBManager.php
index 5d172ba93..0fe7644c4 100644
--- a/include/database/DBManager.php
+++ b/include/database/DBManager.php
@@ -543,7 +543,7 @@ abstract class DBManager
                     continue;
                 }

-                if (isset($data[$field])) {
+                if(isset($data[$field]) && (strlen($data[$field])>0 || $data[$field]===false)) { 
                     // clean the incoming value..
                     $val = from_html($data[$field]);
                 } else {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Branch:Hotfix Status:Assessed PRs that have been tested and confirmed to resolve an issue by a core team member Status: Passed Code Review Mark issue has passed code review reviewed Status: Passed Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saving "0" value in numeric fields when it's empty
5 participants