carrierwaveuploader / carrierwave-mongoid

Mongoid support for CarrierWave
MIT License
355 stars 165 forks source link

MongoDB 3.6 --> Mongo::Error::OperationFailure: Unknown modifier: $pushAll #189

Open Startouf opened 6 years ago

Startouf commented 6 years ago

It seems that the $pushAll operator was removed in MongoDB 3.6, making systematic crashes when trying to update an uploader

My gem/server versions

Here is a full stack trace. At first sight it doesn not seem related to mongoid carrierwave, but the bug only occurs when I try to add an image file so I'm not sure what to think of it

Mongo::Error::OperationFailure: Unknown modifier: $pushAll (9)
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/operation/result.rb:267:in `raise_operation_failure'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/operation/result.rb:263:in `validate!'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/operation/shared/write.rb:42:in `execute'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/collection/view/writable.rb:307:in `block (2 levels) in update_one'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/retryable.rb:158:in `legacy_write_with_retry'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/retryable.rb:106:in `write_with_retry'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/collection/view/writable.rb:295:in `block in update_one'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/cluster.rb:524:in `with_session'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/client.rb:550:in `with_session'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/collection/view.rb:204:in `with_session'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongo-2.6.2/lib/mongo/collection/view/writable.rb:294:in `update_one'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongoid-6.1.1/lib/mongoid/query_cache.rb:182:in `update_one_with_clear_cache'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongoid-6.1.1/lib/mongoid/persistable/updatable.rb:137:in `block in update_document'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongoid-6.1.1/lib/mongoid/persistable/updatable.rb:112:in `block (2 levels) in prepare_update'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.5/lib/active_support/callbacks.rb:126:in `call'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.5/lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
... 8 levels...
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.5/lib/active_support/callbacks.rb:455:in `call'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.5/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.5/lib/active_support/callbacks.rb:750:in `_run_save_callbacks'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.5/lib/active_support/callbacks.rb:90:in `run_callbacks'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongoid-6.1.1/lib/mongoid/interceptable.rb:132:in `run_callbacks'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongoid-6.1.1/lib/mongoid/persistable/updatable.rb:110:in `prepare_update'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongoid-6.1.1/lib/mongoid/persistable/updatable.rb:132:in `update_document'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/mongoid-6.1.1/lib/mongoid/persistable/savable.rb:25:in `save'
    from (irb):38
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/railties-5.0.5/lib/rails/commands/console.rb:65:in `start'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/railties-5.0.5/lib/rails/commands/console_helper.rb:9:in `start'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/railties-5.0.5/lib/rails/commands/commands_tasks.rb:78:in `console'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/railties-5.0.5/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /websites/hermes-production/shared/bundle/ruby/2.3.0/gems/railties-5.0.5/lib/rails/commands.rb:18:in `<top (required)>'
    from bin/rails:14:in `require'
    from bin/rails:14:in `<main>'
rmm5t commented 6 years ago

I think this is an issue with the mongoid (v6) gem itself: https://jira.mongodb.org/browse/MONGOID-4469

Thoughts?

Edit: It looks like mongoid v7 fixes the problem. Is it possible for you to try to upgrade to that?

Startouf commented 6 years ago

I tried but upgrading to Mongoid v7 requires that I upgrade too many other gems. Currently I'm stuck on mongoid 6.1.1 but I'll be working on the upgrade.

I also discovered another problem (which might be fixed with a mongoid upgrade) : It seems like remove_logo! does not seem to work properly on embedded documents

model.nested_document.logo.present? # true
model.nested_document.remove_logo! # true
model.nested_document.save! # true
model.nested_document.logo.present? # false
model.reload
model.nested_document.logo.present? # true

# Note that I also tried saving directly the parent `model.save! # true` which did not work better.

It seems like the logo attributes keeps the value __old__ which causes the method .present? to return true. I did not have this bug with carrierwave < 1.x

Note that the following works :

model.nested_document.remove_attribute('logo') #=> "_old_"
model.nested_document.save!
model.nested_document.company_logo.present? #=> false

I'm not sure if I should open a ticket or wait to see if Mongoid v7 will fix that too

niksosf commented 6 years ago

@Startouf I had the same error and updated Mongoid to 6.4.2 and it went away. Maybe try it out since it's still on the 6.x branch?

Startouf commented 6 years ago

@rmm5t I have migrated to Mongo v7 a couple days ago on our production app (it was quite a pain btw) and the error's gone, and it seems like @niksosf also fixed it by bumping Mongoid6, so I guess we can close ?

Or do we need to enforce some version dependency on the Gemfile to avoid this ?

niksosf commented 6 years ago

I agree I think it’s healthier moving forward that we close this instead of waiting for a fix to carrierwave

Nik So

On Nov 6, 2018, at 6:09 PM, Cyril Duchon-Doris notifications@github.com wrote:

@rmm5t I have migrated to Mongo v7 a couple days ago on our production app (it was quite a pain btw) and the error's gone, and it seems like @niksosf also fixed it by bumping Mongoid6, so I guess we can close ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

rmm5t commented 6 years ago

Thanks for the updates @niksosf and @Startouf. I'm glad things were fixed by the core mongoid gem (both in the v6 and v7 branches of development).

Let me give this some thought as to whether we should modify the gemspec here or not.