Not sure if this is the correct tag - however;
vanilla.rb errors out at line 240 if null date fields. Suggest if statement to replace null with 0000-00-00 00:00:00
Thanks,
Mark
A developer, mmuyskens, reported an error in the vanilla.rb migration script (Post 1) where it failed at line 240 due to null date fields. The user suggested replacing null values with a default timestamp. Another user, zogstrip, noted that null dates might be intentional, especially for required fields like DateInserted, and expressed a preference for the script to fail rather than import bad data (Post 4).
When mmuyskens clarified that the import script halts completely when encountering a single error, preventing any user migration, pfaffman offered an alternative solution: utilizing the DateFirstVisit field as a fallback for missing date_inserted values (Post 7). Despite the discussion, the original poster later returned to the thread with a different database to report a persistent TypeError where nil cannot be converted to a String (Post 8), showing that the issue remains unresolved.
Not sure if this is the correct tag - however;
vanilla.rb errors out at line 240 if null date fields. Suggest if statement to replace null with 0000-00-00 00:00:00
Thanks,
Mark
It depends. Sometimes it makes sense to have a null date. Do you know what the date is for?
If it was the DateInserted, then it was definitely required. I’d rather it blow up (or skip it) rather than importing bad data.
Hmm, maybe inserting the current timestamp in this case would be a better idea - anyways, just throwing this out as an issue really. Having the script stop and not import ANY users doesn’t really work ![]()
Feel free to submit a PR ![]()
If the problem is importing users, you might try using the DateFirstVisit field.
Maybe something like this:
created_at: parse_date(user[:date_inserted] || user[:date_first_visit]),
would work if for those users that don’t have an insert date they do have a first visit date.
Note: I’ve worked mostly with MySQL imports and don’t really understand what gets built in parse_file. This could be completely wrong and I have no way to test it.
I know i’m bumping my own thread but round 2 for me. Different database. Any input? We have no null date fields;
discourse@dev-app:/var/www/discourse$ RAILS_ENV=production ruby script/import_scripts/vanilla.rb /shared/export.txt
loading existing groups...
loading existing users...
loading existing categories...
loading existing posts...
loading existing topics...
parsing file...
reading file...
parsing categories...
parsing comments...
parsing conversations...
parsing conversation_messages...
parsing discussions...
parsing permissions...
parsing roles...
parsing users...
parsing user_conversations...
parsing user_discussions...
parsing user_roles...
importing users...
script/import_scripts/vanilla.rb:240:in `strptime': no implicit conversion of nil into String (TypeError)
from script/import_scripts/vanilla.rb:240:in `parse_date'
from script/import_scripts/vanilla.rb:101:in `block in import_users'
from /var/www/discourse/script/import_scripts/base.rb:242:in `block in create_users'
from /var/www/discourse/script/import_scripts/base.rb:241:in `each'
from /var/www/discourse/script/import_scripts/base.rb:241:in `create_users'
from script/import_scripts/vanilla.rb:87:in `import_users'
from script/import_scripts/vanilla.rb:19:in `execute'
from /var/www/discourse/script/import_scripts/base.rb:45:in `perform'
from script/import_scripts/vanilla.rb:254:in `<main>'
discourse@dev-app:/var/www/discourse$