No Code Attached Yet bug
avatar Giuse69
Giuse69
17 Aug 2023

Problem identified

A field in a table may have NULL values (that is even more important since now every field must have a default value so for numerical fields NULL is fundamental, since 0 is wrong and empty is not a number).
Now when the user edit an object and wants to remove the value of a numeric field, in a point of the process the form is sent to the bind function in "libraries/src/Table/Table.php", that replaces the values currently stored in the DB with the new values coming from the form.
The problem is that if a field has a new value of "null" we have 2 options:

  • an empty value is passed => that causes an error, since we cannot store an empty string into a numerical field
  • a NULL value is passed => that is the intended value, but the bind function of Table.php in line 658 has
    if(isset($src[$k]))
    so every empty value is not used, and current value of the field in the DB is used instead of the new value from the form.

Proposed solution / Open questions

Why filtering OUT null values? Is it a sort of a protection for special situations that we need to keep or can we remove it? Currently extensions cannot ask Joomla to save a NULL value.
Or checking if the field is NULLable from the field properties in the DB?

thanks

avatar Giuse69 Giuse69 - open - 17 Aug 2023
avatar joomla-cms-bot joomla-cms-bot - change - 17 Aug 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 17 Aug 2023
avatar Giuse69 Giuse69 - change - 17 Aug 2023
The description was changed
avatar Giuse69 Giuse69 - edited - 17 Aug 2023
avatar alikon
alikon - comment - 18 Aug 2023

sorry if I misunderstood
but with this snippet i'm unable to reproduce

        $contentTable = Table::getInstance('Content', 'JTable');
        $contentTable->load(29);  // an id where checked_out is a number
        $contentTable->checked_out = NULL;
        $data = ArrayHelper::fromObject($contentTable);
        $contentTable->bind($data);
        $contentTable->save($data);

checked_out is updated to NULL as expected

avatar alikon
alikon - comment - 18 Aug 2023

similar to #37956

avatar Giuse69
Giuse69 - comment - 18 Aug 2023

yes, thanks Nicola. The issues arises when editing an existing object that has a non null value and you want to set it to null, the isset() check discard the binding for that value. I see that a solution was proposed but we were waiting for a "major" release, maybe 4.4? I dont think there is a severe backward problem with it, what do you think?

avatar Hackwar Hackwar - change - 21 Aug 2023
Labels Added: bug
avatar Hackwar Hackwar - labeled - 21 Aug 2023

Add a Comment

Login with GitHub to post a comment