I am attempting to use a unix timestamp Date field on accounts, but when attempting to save any new accounts I am receiving the following error:
PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'field_reg_date_value' at row 1: INSERT INTO {field_data_field_reg_date} (entity_type, entity_id, revision_id, bundle, delta, language, field_reg_date_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] => user [:db_insert_placeholder_1] => 128 [:db_insert_placeholder_2] => 128 [:db_insert_placeholder_3] => user [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 2013-01-15 17:00 ) in field_sql_storage_field_storage_write() (line 448 of /Sites/think2perform/modules/field/modules/field_sql_storage/field_sql_storage.module).
I'm not exactly sure, but it seems as if the date is not being converted to a timestamp format that the database is expecting.
If I change the field to a standard Date field (not unix timestamp), I can save a new Account without issue.
Additionally, I added the same field to a Node (instead of a user account) and was able to save without getting the PDOException.
This error persists through creating new fields, but always only effects Accounts.
Please let me know if I can provide additional details!
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | 1889744-32-PDOException-when-saving-date-as-unix-timestamp.patch | 829 bytes | mariagwyn |
| #27 | date-1889744.patch | 1016 bytes | tatyana |
| #23 | date-1889744.patch | 1.31 KB | tatyana |
| #11 | date-1889744-11-PDOException-when-saving-date-as-unix-timestamp.patch | 821 bytes | mstrelan |
Comments
Comment #1
tormu commentedSame problem. I have the same field in a local environment and now threw that into production site via feature and get this error in the production site - but not on a local site.
Also added a new field (date, unix stamp) manually through GUI and get the same error for that field also.
PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'field_active_timestamp_value' at row 1: INSERT INTO {field_data_field_active_timestamp} (entity_type, entity_id, revision_id, bundle, delta, language, field_active_timestamp_value, field_active_timestamp_value2) 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, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 47250 [:db_insert_placeholder_2] => 53796 [:db_insert_placeholder_3] => broadcast [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 2013-02-21 12:32 [:db_insert_placeholder_7] => 2013-02-21 13:32 ) funktiossa field_sql_storage_field_storage_write() (rivi 448 tiedostossa /modules/field/modules/field_sql_storage/field_sql_storage.module).
EDIT 2013-03-06: problem went away. No idea how and why :((((
Comment #2
titi88888888 commentedI just encoutered the exact same probmem using Date field with unix stamp.
The data cannot be injected in the DB...
I am not sure, but when you see this in the error message :
[:db_insert_placeholder_6] => 2013-02-21 12:32 [:db_insert_placeholder_7] => 2013-02-21 13:32
...you guess that drupal tries to inject a date that is not in unix-timestamp format in a column that is supposed to receive only unixtimestamp format INT(11).
Also, what is really strange, is that this field type (unix timestamp) used to work a few days ago. This morning I wake up, and the field doesn't work anymore.
Do someone has a clue ?
Comment #3
tregismoreira commentedSame error here. Do you solved it?
EDIT: As my debugs, (like @tormu and @titi88888888 said) the value is not being sent as timestamp (it's being sent as the format defined in the instance field). That is what is causing the problem. But in my case, the error only happens on a particular bundle (strange, not?). I tested this field (exactly the same field) in other 2 bundles and functioned normally. I will continue to investigate the problem...
Comment #4
tregismoreira commentedHey guys. My workaround was to get the field value (which is formated as d/m/Y) in form #validate and force the timestamp value with strtotime(). I hope to find a permanent solution soon. If anyone finds, please let me (us) know ;)
Comment #5
ericmaster commentedHey guys, I was getting this issue too and after a whole day debugging I finally found the cause, still don't know how to solve it yet though. In my case the problem is caused because I'm using conditional fields module together with date module. Problem arises because date element validation handler changes the value from datetime format to datestamp format, but in around line 521 of date_elements.inc file there is the following
it triggers the action depending if ANY error was triggered by any other field before, now, around line 789 of conditional_fields.module there is the following
so "invalid" errors are cleared and the form submits but date field assumed there was an error so it never "processed" the date field value so it's passed through as is, which is in datetime format. Still not sure how to fix this but if you have any idea let me (us) know. Btw, I tried to set a negative weight to the conditional fields module but it didn't work.
Comment #6
loze commentedI can confirm that this indeed does have to do with conditional fields.
Even if the date field is not in any of the conditions.
Did you ever figure out how to resolve this?
Comment #7
loze commented@Ericmaster, actually I think you may have had that backwards. I set the conditional fields module to a lower weight (30, it was set to 10 originally) and I am now able to save unix timesamp date fields with conditional fields.
Thanks for that clue.
Comment #8
ericmaster commentedGood to hear that modules weight worked for you, sorry for not being able to respond quickly. At the end I workaround it by setting all fields as not required and redo validation in a custom validation handler, not the best solution of course, but needed to close that bug asap.
Comment #9
daulet2030 commentedAny update on this issue? I have required fields, which are made hidden by conditional field module in certain conditions, of course that will bring validation errors when saving form, those errors are removed by conditional field module, but the date field is not converted into UNIX format. Is there a way to process all visible fields, before removing error?
Setting module priority doesn't help. I had to remove "Required field" on all fields to make this error go away :/
Comment #10
criznach commented#4 worked for me. In my case, the workaround code in a custom module looks like this...
Comment #11
mstrelan commentedI am having the same issue updating a user via Services. With the workarounds discussed you will likely face issues with timezones.
The attached patch fixes the issue for me. The issue being that
$form_input[$field_name]is empty but$form_values[$field_name]is not. Please confirm if this solves the problem with conditional fields.An alternative would be to ensure that
date_hidden_element()returns TRUE. To achieve that one of the following conditions must be met.In my scenario that probably doesn't make sense, as Services has no idea that a user profile might have a date field (or that the date module even exists).
The patch could also be rewritten to share the same return statement at the top of the function, but that would require moving the "expensive"
drupal_array_get_nested_value()calls to the top.Comment #12
mstrelan commentedOne more approach that could solve this is to ensure $form_input[$field_name] is always set before this function is called, but I have no idea where to start to achieve that.
Comment #14
fox_01 commentedI got the same problem but only after upgrading conditional fields to latest dev for testing. With version 7.x-3.0-alpha1 of conditional fields the problem is NOT present
Comment #15
fox_01 commentedShort update:
I have recreated my conditons and i can't reproduce the error now. Can anyone confirm this?
Comment #16
joel_osc commentedI am getting the error with both alpha-1 and 3.x-dev releases of conditional_fields.
Comment #17
fox_01 commentedIt may have solved the problem that i was recreating the conditions while migrating between the versions
Comment #18
joel_osc commentedThanks @Ericmaster for his work tracking this down! Changing the required fields to not required and creating a custom validation handler is a good workaround.
I am not sure how changing module order would fix this, as I believe that conditional_fields_form_validate needs to run after node_form_validate and it is node_form_validate that executes the field element validation. The problem is that if you have a required field that is hidden by conditional_fields AND is validated prior to a date field then the date module in date_combo_validate will not convert the date strings to timestamps and a PDO Exception will be thrown.
One possible (bad) solution is to just change the elseif to an else in the following code and let the duplicate errors fly:
However, I am thinking there should be better way to avoid showing duplicate errors on nested elements and not throw exceptions when using conditional_fields.
Comment #19
keopxProblem continues on newest version 7.x-2.8
Change priority because I think it's a big problem if you decided used this date format.
Comment #20
samuel.mortensonThe patch from #11 fixed an issue I was having with updating a Node that included this type via the Services module.
Comment #21
eanushan commentedI had the same issue as #20. Was using Services module. User profile had a "Date of Birth" field of type date, storing as unix timestamp. The patch in #11 fixed the issue.
Comment #23
tatyana commentedWe had the same issue as described in #5 and #18, which appears to be different from the issue with Services module and the patch from #11 doesnt fix it.
New patch with suggested fix is attached
Comment #26
justinen commentedI can confirm that the patch from #11 fixes the Services module issue. I was not using the conditional fields module.
Comment #27
tatyana commentedbetter patch format
Comment #28
KristineC commented#27 works perfect! Thanks, tatyana. I don't have the service module enabled, but conditional fields were used.
Comment #29
samuel.mortensonMoving back to needs review, state was not changed with last patch submission.
Comment #32
mariagwyn commentedChanges in #11 worked, but patch didn't apply to 7.x-2.9. I pulled a new patch.
Comment #33
majdi commentedPatch #27 works fine , patch #32 not working for me
Comment #34
majdi commentedPatch #32 did not solve the problem with 7.x-2.9 and conditional fields is enabled
Comment #35
nancydruYes, #27 worked; #32 did not.
Comment #36
samuel.mortensonMoving into RTBC. Change seems good and multiple users have confirmed that the patch in #27 works.
Comment #37
cafuego commentedI've applied the patch from #27 to 7x-2.x, which applied OK with a few lines of offset. I did make a small cosmetic code change:
Thanks for your work on this!
Comment #40
eanushan commented#32 is necessary for compatibility with the Services module. Can we take a look at merging in #32 as well?
Comment #42
podarok#32 merged. Thanks.
Comment #44
evadex commentedThe problem is still relevant.
PDOException: SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'field_date_value' at row 1: INSERT INTO {field_data_field_date} (entity_type, entity_id, revision_id, bundle, delta, language, field_date_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] => node [:db_insert_placeholder_1] => 70 [:db_insert_placeholder_2] => 70 [:db_insert_placeholder_3] => event [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => -62165769799 ) в функции field_sql_storage_field_storage_write() (строка 514 в файле /home/srv66997/lukmkp.ru/modules/field/modules/field_sql_storage/field_sql_storage.module).
see the data field value is negative. How can this be?
Comment #45
quotesbro commented@evadex It was released just 2 weeks ago: https://www.drupal.org/project/date/releases/7.x-2.10
Comment #46
Anonymous (not verified) commentedStill an issue.