Looks like the ctools exportables assumes that if a field type is a tiny int that it is a boolean field. This means that fields that might contain tiny integer values like 0, 1, 2 or 3 end up being exported as TRUE or FALSE. Here is the code where this happens.

In my opinion, this logic should just be removed. I can't imagine any case where exporting a boolean value as 0 or 1 accidentally could cause problems, but I foresee all sorts of problems when a bona fide int is exported as boolean.

Thoughts?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

q0rban’s picture

Title: Tiny int is not always a boolean » Tiny int should not be exported as a boolean
q0rban’s picture

Status: Active » Needs review
FileSize
1.21 KB
q0rban’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
FileSize
1.22 KB

Whoops, misspoke in my code comments. Also attached patch is against 8.x-1.x.

merlinofchaos’s picture

There needs to be some way to preserve the existing behavior. TRUE vs FALSE is very valuable. If it means we have to add an extra field in imports to say "Yes this is a boolean" that's fine, but I think that's valuable.

merlinofchaos’s picture

There is no point in doing this in 8.x as this entire system is being replaced by CMI.

jzornig’s picture

I just got bitten by this with the ldap module. A tiny int field that should have a value of 4 is exported in a feature as true and imported as 1.

jzornig’s picture

So what is the solution here? The Drupal schema api doesn't even define a Boolean type or TRUE/FALSE values. If ctools assumes that any TINYINT is in fact a boolean then should TINYINT never be used as an integer type field?

merlinofchaos’s picture

The solution is to probably add a flag that will tell it not to export a tinyint as a boolean value (which it usually is, but obviously not 100% of the time). Maybe 'bool' => FALSE or something, and make sure it defaults to true in ctools_export_get_schema().

jzornig’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
FileSize
640 bytes

I've rolled a new patch against 7.x-1.x-dev that treats tiny int fields as boolean if the value is 0 or 1 but as an integer for other values. It fixes the problem I was having in features with ldap.

byrond’s picture

Status: Needs review » Needs work

I assume you're having the same issue we are with Features and LDAP. Features will export the 'bind_method' of an LDAP server configuration as a boolean. The problem with this patch is that TRUE doesn't map back to 1. For example, bind_method=TRUE does not select the same item as bind_method=1. So, the patch will only work for features where that value is not 1. I don't see a case where bind_method=FALSE would ever be exported, since the items are given values 1-4, where bind_method=0 will select the same item as bind_method=1.

I haven't tested any other examples where tinyints are not used for boolean values. In this case, I wonder if Features should be updated to use something other than a tinyint for bind_method.

jzornig’s picture

Status: Needs work » Needs review

I've been revisiting this again. The issue raised in #12 is caused by an exported TRUE being imported as TRUE rather than as 1. If you visit the edit page that TRUE gets used as the #default_value for the form item, in the case of ldap_servers bind_method this is a radio checkbox. The result it that all the inputs are set to checked but it being a radio only the last is set. The only solution is to never export tinyints as TRUE/FALSE values but only as integers.
There is no way to set a flag as suggested in #4 because there is nowhere defined in drupal that a tinyiny should be treated as a boolean, because booleans don't exist in the schema. You can always use an int in place of a boolean and get the correct behaviour but the reverse in not true. E.g. setting a #default_value in a form to TRUE has a very different effect to setting it to 1.
So the patch in #3 should be used rather than the patch in #11.

merlinofchaos’s picture

Yes there is a way to set a flag; export system has other flags on occasion in field schema data. We have flexibility there.

netsensei’s picture

I hit this issue while working on #717874: Provide exportables for Mollom forms I had to use the "export callback" property on a tinyint field as a work around. I agree with merlinofchaos: adding a flag to explicitly denote that a tiny int sized field is or is not a boolean.

Patch introduces a new "boolean" property to the schema and sets it default to FALSE (As per #10) ctools_export_object uses the flag to cast the value to either an int or a boolean.

merlinofchaos’s picture

netsensei: I like the inheritance you put into that patch very much.

The 'boolean' value needs to be documented in help/export.html I think, but otherwise this patch looks really solid.

merlinofchaos’s picture

Oh and I think it needs to default to TRUE in order to avoid changing behavior on existing installations.

netsensei’s picture

Okay. Done!

Added to the patch:

* Boolean defaults to TRUE
* Documentation snippet in help/export.html

pobster’s picture

What is preventing this from being committed? It's an annoying bug this...

Thanks,

Pobster

Jelle_S’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good and I can confirm it's working.

Jelle_S’s picture

Issue summary: View changes

Fixed my verbiage surrounding the last sentence.

japerry’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.