Topic: Weird ActiveRecord behavior: fails with 'database is locked'

Hi! I'm getting this error: SQLite3::BusyException: database is locked: commit transaction (ActiveRecord::StatementInvalid)

with this code:
    w=Word.where(:language=>lang, :word=>word).first
    if w == nil
        w=Word.new
        w.language = lang
        w.word = word
        w.save
    end
    w.id

there are no threads. so the error is pretty weird. this is stack trace:

    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:108:in `block in each'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:107:in `loop'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:107:in `each'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:149:in `map'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:149:in `block in execute'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:95:in `prepare'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:134:in `execute'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:506:in `commit'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:368:in `block in commit_db_transaction'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:368:in `commit_db_transaction'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:176:in `perform_commit'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:116:in `commit'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:236:in `commit_transaction'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:216:in `within_new_transaction'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/transactions.rb:209:in `transaction'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/transactions.rb:270:in `block in save'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/transactions.rb:281:in `rollback_active_record_state!'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/transactions.rb:269:in `save'
    from /home/attilio/Dropbox/Ruby/Ants web/ar_stuff.rb:268:in `save'
    from maintenance.rb:26:in `ar_get_word_id'
    from maintenance.rb:15:in `rescue in get_word_id'
    from maintenance.rb:9:in `get_word_id'
    from maintenance.rb:46:in `block (2 levels) in <main>'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:142:in `block (2 levels) in execute'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:110:in `block in each'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:107:in `loop'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:107:in `each'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:140:in `block in execute'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:95:in `prepare'
    from /home/attilio/.rvm/gems/ruby-2.0.0-p195/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:134:in `execute'
    from maintenance.rb:42:in `block in <main>'
    from maintenance.rb:41:in `catch'
    from maintenance.rb:41:in `<main>'

any ideas?