Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3610

readonly attributes can still be modified with (some?) atomic operations

    • Type: Icon: Task Task
    • Resolution: Done
    • 4.0.0 final
    • Affects Version/s: None
    • Component/s: None
    • None

      Not sure if this is a bug or feature, but attributes marked as read-only can still be modified using #inc (and presumably other) atomic operations:

      Against master (@ 030442e):

      require "bundler/setup"
      require "mongoid"
      
      Mongoid::Config.connect_to("mongoid_test")
      
      class Foo
        include Mongoid::Document
      
        field :bar, type: Integer
        attr_readonly :bar
      end
      
      foo = Foo.create(bar: 5)
      foo.reload.bar # => 5 (as expected)
      
      foo.update_attributes(bar: 6)
      foo.reload.bar # => 5 (as expected)
      
      foo.set(bar: 6)
      foo.reload.bar # => 5 (as expected)
      
      foo.inc(bar: 1)
      foo.reload.bar # => 6 (shouldn't happen!)
      

      If that's by design, it should probably be documented.

            Assignee:
            Unassigned Unassigned
            Reporter:
            niels Niels Ganser
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: