Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comment | File | Size | Author |
---|---|---|---|
#18 | 1760752-18-tiny-int-boolean.patch | 2.24 KB | netsensei |
#15 | 1760752-15-tiny-int-boolean.patch | 1.13 KB | netsensei |
#11 | ctools-1760752-tiny-ints-4.patch | 640 bytes | jzornig |
#3 | ctools-1760752-tiny-ints-3.patch | 1.22 KB | q0rban |
#2 | ctools-1760752-tiny-ints-2.patch | 1.21 KB | q0rban |
Comments
Comment #1
q0rban CreditAttribution: q0rban commentedComment #2
q0rban CreditAttribution: q0rban commentedComment #3
q0rban CreditAttribution: q0rban commentedWhoops, misspoke in my code comments. Also attached patch is against 8.x-1.x.
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedThere 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.
Comment #5
merlinofchaos CreditAttribution: merlinofchaos commentedThere is no point in doing this in 8.x as this entire system is being replaced by CMI.
Comment #6
jzornig CreditAttribution: jzornig commentedI 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.
Comment #9
jzornig CreditAttribution: jzornig commentedSo 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?
Comment #10
merlinofchaos CreditAttribution: merlinofchaos commentedThe 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().
Comment #11
jzornig CreditAttribution: jzornig commentedI'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.
Comment #12
byrond CreditAttribution: byrond commentedI 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.
Comment #13
jzornig CreditAttribution: jzornig commentedI'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.
Comment #14
merlinofchaos CreditAttribution: merlinofchaos commentedYes there is a way to set a flag; export system has other flags on occasion in field schema data. We have flexibility there.
Comment #15
netsensei CreditAttribution: netsensei commentedI 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.
Comment #16
merlinofchaos CreditAttribution: merlinofchaos commentednetsensei: 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.
Comment #17
merlinofchaos CreditAttribution: merlinofchaos commentedOh and I think it needs to default to TRUE in order to avoid changing behavior on existing installations.
Comment #18
netsensei CreditAttribution: netsensei commentedOkay. Done!
Added to the patch:
* Boolean defaults to TRUE
* Documentation snippet in help/export.html
Comment #19
pobster CreditAttribution: pobster commentedWhat is preventing this from being committed? It's an annoying bug this...
Thanks,
Pobster
Comment #20
Jelle_SPatch looks good and I can confirm it's working.
Comment #20.0
Jelle_SFixed my verbiage surrounding the last sentence.
Comment #21
japerryTested, Fixed, and committed:
http://drupalcode.org/project/ctools.git/commit/965db49b093d52fb944af7d7...