No data added to {twitter_account}

webchick - February 22, 2009 - 01:39
Project:Twitter
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:duplicate
Description

See screenshot:
No name and description for you!

#1

webchick - February 22, 2009 - 03:12
Title:name and description are blank» name and description are blank when user has no tweets yet

Ok, figured out the problem. In twitter_user_save(), there's this logic:

<?php
   
if (!empty($statuses)) {
     
twitter_cache_account($statuses[0]['account']);
     
twitter_touch_account($account['screen_name']);
    }
?>

Since my twitter account has no tweets yet, $statuses is indeed empty. As a consequence, no information gets saved to the twitter_account table, so the table comes back blank.

I see this was introduced here: http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/twitter/twi..., the log message of which reads "Compatability with the latest Views 2 dev release and the forthcoming RC2." I assume this means that Views freaks out when there's info in this table, but not any info in the twitter table? Still, on an initial import, this really looks odd.

I'm not sure if the answer is to run this logic on initial account setup regardless, or if it's just to put some logic in the form validation that prevents new accounts from being imported, but at least this is now documented for the next poor slob. :)

#2

webchick - February 22, 2009 - 03:20
Title:name and description are blank when user has no tweets yet» No data added to {twitter_account} when account has no tweets yet

More descriptive title.

#3

jaydub - March 1, 2009 - 01:08

ran into this too. I figured out what's missing.

The record written to twitter_account is using drupal_write_record. The array that is passed to drupal_write_record has all the fields of the twitter_account table inside except for the 'last_refreshed' field.

At least for me, there is no last_refreshed field that is returned from Twitter when fetching the statuses array. There is a field called 'created_time' but it's outside of the 'account' array returned by Twitter. Since last_refreshed is a required field in the twitter_account table and there is no DEFAULT, the drupal_write_record is failing.

You can test this by changing the twitter_cache_account function in twitter.inc from:

function twitter_cache_account($twitter_account = array()) {
  db_query("DELETE FROM {twitter_account} WHERE twitter_uid = %d", $twitter_account['twitter_uid']);
  drupal_write_record('twitter_account', $twitter_account);
}

to

function twitter_cache_account($twitter_account = array()) {
  db_query("DELETE FROM {twitter_account} WHERE twitter_uid = %d", $twitter_account['twitter_uid']);
  $twitter_account['last_refresh'] = time();
  drupal_write_record('twitter_account', $twitter_account);
}

So the logic needs to be rewritten to get at the created_time Twitter field to use in the account array passed to drupal_write_record.

#4

jaydub - March 11, 2009 - 20:11

#5

gaele - March 15, 2009 - 00:24
Title:No data added to {twitter_account} when account has no tweets yet» No data added to {twitter_account}
Priority:normal» critical

Another poor slob here ;-)

Data is added to {twitter_user} but not to {twitter_account}:

  1. when the account has no tweets yet
  2. when the account is protected and the user forgets to enter the password
  3. when the user makes a typo in the account name

In all these cases name and description are blank, the user has no idea what is happening, and is unable to correct the situation.

What's more:

  • trying this several times results in only one line with blank name and description (though there will be several records in {twitter_user})
  • marking "delete" on the empty account followed by "Save changes" results in deletion of all accounts from {twitter_user} (but not from {twitter_account}). So if you add a correct account, then another account with a typo, and then delete the blank account, the correct account will be gone too.

#6

Shiny - June 1, 2009 - 23:55

subscribing

#7

eaton - July 2, 2009 - 13:05
Status:active» duplicate

Appears to be a duplicate of #301317: SQL errors on editing Twitter Accounts

 
 

Drupal is a registered trademark of Dries Buytaert.