Adding field to existing table.

4
I added a boolean with default value false to an existing table. This was synchronized to my MS SQL Server database, of course. But the value of the new fields in existing records was NULL, not false. So the logic in my microflow, based on it being false, didn't work before I had used the SQL Server Management Console to change them to false. In my opinion, when adding fields to an existing table, the Mendix-runtime should fill them with the default values specified in the model. That's the essence of a default, isn't it? Is the current behavior by design, or can I consider it a bug?
asked
3 answers
6

It was by design (a boolean in a microflow could also have the value empty), but this has changed in the latest Mendix version (2.4.5): now a boolean can only have the values true and false, including the values in the database.

From the 2.4.5 changelog:

MXDN 3518: Booleans should only have the values true or false. However, it was possible to set a Boolean value to empty, leading to unexpected behaviour. We have implemented the following fixes:

  • The XAS throws an exception if an exclusive split in a microflow encouters a Boolean with value 'empty'.
  • Newly added attributes now get default values in the database on synchronisation for each existing row in the database (not only Booleans, but all attribute types).
  • Backward compatibility fix: all Boolean values which are empty in the database will be set to the default value.
  • We have added a consistency check in the Modeler preventing you from setting a Boolean attribute to empty. It is also not possible to compare a Boolean attribute with empty or NULL.
  • The following error will be logged if you at runtime (e.g. in Java code) try to set a Boolean member to NULL: java.lang.!IllegalArgumentException: Boolean member can not be set to null

If you're already using this version, then you could've discovered a bug.

answered
1

Thanks you for reporting this.

This was a known issue and was fixed in 2.4.5. (Thanks Alexander for reminding me of the correct version :)

Remember that you can report bugs into the MxDN Partner Portal under 'Incidents'. The R&D departement will evaluate these and if confirmed, will assign them to be fixed. You can also see what bugs have been reported and are schedules to be fixed (and for what version).

For older versions I advice you change your boolean check to do:

$variable = false or $variable = empty

This should fix the problem. In 2.5 the Modeler will convert this into an error, make it clear that you can remove it again.

answered
0

Indeed I'm using 2.4.4.1. Nice to see it's fixed in a future version.

answered