Steps to reproduce:

Add a Boolean field to a content type. In the 'Options' text area enter two values, e.g.,
Options:
True
False

Create Content > You Content Type

Select one of the options. Submit.

Observe:

* PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'False' for column 'field_torf_value' at row 1: INSERT INTO {field_data_field_torf} (etid, entity_id, revision_id, bundle, delta, language, field_torf_value) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => custom [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => zxx [:db_insert_placeholder_6] => False ) in field_sql_storage_field_storage_write() (line 421 of /var/www/vc/drupal-head/drupal/modules/field/modules/field_sql_storage/field_sql_storage.module).

The website encountered an unexpected error. Please try again later.

Comments

johanneshahn’s picture

at the field description where you define the key|value pairs

i notice following text:

"The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and must be a numeric value. The label is optional, and the key will be used as the label if no label is specified."

think the best way is to check the correct formatting of user input
before saving the field.

johanneshahn’s picture

StatusFileSize
new1.1 KB

try this path

johanneshahn’s picture

Assigned: Unassigned » johanneshahn
Status: Active » Needs review
StatusFileSize
new1.1 KB

try again

Status: Needs review » Needs work

The last submitted patch failed testing.

matt2000’s picture

Priority: Normal » Critical

this needs to be revisited before release...

yched’s picture

Status: Needs work » Needs review
StatusFileSize
new2.12 KB

That one should apply. Additionally, checks that we have no more or no less than 2 values.

Status: Needs review » Needs work

The last submitted patch failed testing.

Status: Needs work » Needs review

yched requested that failed test be re-tested.

matt2000’s picture

Status: Needs review » Reviewed & tested by the community

This looks good, and solves the bug from a technical standpoint.

The form description text could probably also use some love to prevent this error from appearing in the first place, but that's a separate issue.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Let's get tests for this, please.

matt2000’s picture

Status: Needs work » Needs review
StatusFileSize
new3.99 KB

My first time writing tests. How's this?

yched’s picture

Status: Needs review » Needs work

Yay, thanks for stepping in Matt !

+++ modules/field_ui/field_ui.test	20 Nov 2009 22:02:31 -0000
@@ -207,4 +207,41 @@ class FieldUITestCase extends DrupalWebT
+  function testBooleanOptions() {

The test should go in field/modules/list/list.test rather than in field_ui/field_ui.test.
This will probably warrant a separate testcase class, with its own setUp() inspired from the one in field_ui.test

+++ modules/field_ui/field_ui.test	20 Nov 2009 22:02:31 -0000
@@ -207,4 +207,41 @@ class FieldUITestCase extends DrupalWebT
+    //check missing option

Formatting + misses trailing point.

+ ideally, we would also test the other failures for other 'list' types ;-)

This review is powered by Dreditor.

matt2000’s picture

I wondered about which module to place these test with, but they only apply to the form that's generated by field_ui; i.e., if field UI module is not being used, there is no reason to run these test, I think?

Which brings up the idea... do we need some kind of error handling or unit tests for the API functions to make sure API users don't make the same mistake?

yched’s picture

but they only apply to the form that's generated by field_ui

Not exactly. The code is in a hook that is called by field_ui and won't be executed if field_ui isn't enabled, but this doesn't change the fact that it's code from list.module that is being tested.
Exact same reason why other list tests, text tests, options tests, etc. are in the field type modules, and not in field API.

do we need some kind of error handling or unit tests for the API functions to make sure API users don't make the same mistake?

You mean field_create_field() should throw an exception if the list of values is not valid ? Well, theoretically yes. Er, I'm not sure we'll be there in D7, though.

matt2000’s picture

Assigned: johanneshahn » matt2000
Status: Needs work » Needs review
StatusFileSize
new5.86 KB

OK, how about this?

yched’s picture

Great ! Minor remarks:

+++ modules/field/modules/list/list.test	23 Nov 2009 19:43:48 -0000
@@ -85,5 +85,96 @@ class ListFieldTestCase extends DrupalWe
+      'group' => 'Field UI',

group should be 'Field Types'

+++ modules/field/modules/list/list.test	23 Nov 2009 19:43:48 -0000
@@ -85,5 +85,96 @@ class ListFieldTestCase extends DrupalWe
+    //Test Number type.

Nitpick: "Number" field type is something else.
I'd suggest "Test 'List (number)' field type.
Same remark applies to "Test Text type below".

As a side note: those 3 different 'list' types are on their way out: #622614-3: Consider reducing the number of field types

+++ modules/field/modules/list/list.test	23 Nov 2009 19:43:48 -0000
@@ -85,5 +85,96 @@ class ListFieldTestCase extends DrupalWe
+    $valid_types = array('list',
+                         'list_boolean',
+                         'list_number',
+                         'list_text',
+                         );
+    if (!in_array($type, $valid_types)) return FALSE;

That check is overkill. Plz just remove it.

Really nitpick: please put the tests in the following order:
- List
- List (number)
- List (text)
- Boolean

Once those are fixed, this is RTBC.

This review is powered by Dreditor.

matt2000’s picture

StatusFileSize
new5.67 KB

As requested...

yched’s picture

Oops, 2 last really minor details.

+++ modules/field/modules/list/list.test	23 Nov 2009 23:33:26 -0000
@@ -85,5 +85,89 @@ class ListFieldTestCase extends DrupalWe
+      'name' => 'List Field UI tests',

Don't capitalize the F(ield), to be consistent with the existing 'List field tests'

+++ modules/field/modules/list/list.test	23 Nov 2009 23:33:26 -0000
@@ -85,5 +85,89 @@ class ListFieldTestCase extends DrupalWe
+    // Test 'List (number)' field type.

The other comments don't have the word 'field'

This review is powered by Dreditor.

matt2000’s picture

StatusFileSize
new5.69 KB

(2) I noticed that when I looked at my last attachment after posting, but hoped it would sneak by.... ;-)

yched’s picture

Status: Needs review » Reviewed & tested by the community

:-p

Thanks matt !

dries’s picture

Status: Reviewed & tested by the community » Fixed

Looks great. Great tests too, matt. Committed to CVS HEAD.

yched’s picture

Status: Fixed » Reviewed & tested by the community
StatusFileSize
new2.91 KB

Quickfix: test category should be 'Field Types', not 'Field types'. Now we have both on admin/config/development/testing (and it causes the JS expand/collapse to act strangely BTW).

+ trailing whitespace fixes.
hint to @matt2000 for later patches: would be great if you configured your IDE to remove them automatically on file save ;-)

matt2000’s picture

Done. Thanks for the tip.

Also, the quickfix patch looks good, so RTBC++.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Well, actually, core's capitalization standard is "Sentence case", so we should fix the one that are "Field Types" to "Field types" so they're all consistent.

yched’s picture

Status: Needs work » Fixed

re @webchick #24: OK - #658358: inconsistencies in field type tests 'Group'.
Setting this one back to 'fixed'.

Status: Fixed » Closed (fixed)
Issue tags: -Needs tests

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