{"action":"created","issue":{"url":"https://api.github.com/repos/mongoid/mongoid/issues/4030","labels_url":"https://api.github.com/repos/mongoid/mongoid/issues/4030/labels{/name}","comments_url":"https://api.github.com/repos/mongoid/mongoid/issues/4030/comments","events_url":"https://api.github.com/repos/mongoid/mongoid/issues/4030/events","html_url":"https://github.com/mongoid/mongoid/issues/4030","id":67191747,"number":4030,"title":"Dup/clone of a document that has old fields causes an error unless you include Mongoid::Attributes::Dynamic","user":{"login":"jonhyman","id":832655,"avatar_url":"https://avatars.githubusercontent.com/u/832655?v=3","gravatar_id":"","url":"https://api.github.com/users/jonhyman","html_url":"https://github.com/jonhyman","followers_url":"https://api.github.com/users/jonhyman/followers","following_url":"https://api.github.com/users/jonhyman/following{/other_user}","gists_url":"https://api.github.com/users/jonhyman/gists{/gist_id}","starred_url":"https://api.github.com/users/jonhyman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonhyman/subscriptions","organizations_url":"https://api.github.com/users/jonhyman/orgs","repos_url":"https://api.github.com/users/jonhyman/repos","events_url":"https://api.github.com/users/jonhyman/events{/privacy}","received_events_url":"https://api.github.com/users/jonhyman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/mongoid/mongoid/milestones/72","html_url":"https://github.com/mongoid/mongoid/milestones/5.0.0","labels_url":"https://api.github.com/repos/mongoid/mongoid/milestones/72/labels","id":429552,"number":72,"title":"5.0.0","description":"Integration with 10gen Ruby driver, retirement of Moped.","creator":{"login":"durran","id":9030,"avatar_url":"https://avatars.githubusercontent.com/u/9030?v=3","gravatar_id":"","url":"https://api.github.com/users/durran","html_url":"https://github.com/durran","followers_url":"https://api.github.com/users/durran/followers","following_url":"https://api.github.com/users/durran/following{/other_user}","gists_url":"https://api.github.com/users/durran/gists{/gist_id}","starred_url":"https://api.github.com/users/durran/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/durran/subscriptions","organizations_url":"https://api.github.com/users/durran/orgs","repos_url":"https://api.github.com/users/durran/repos","events_url":"https://api.github.com/users/durran/events{/privacy}","received_events_url":"https://api.github.com/users/durran/received_events","type":"User","site_admin":false},"open_issues":41,"closed_issues":0,"state":"open","created_at":"2013-09-17T09:14:09Z","updated_at":"2015-05-05T18:38:12Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2015-04-08T18:36:55Z","updated_at":"2015-05-06T07:09:30Z","closed_at":null,"body":"One of the greatest things about MongoDB is the flexible schema. If you have a model that has some fields and you later decide to remove those fields without doing a migration and `$unset`'ing them from the documents, you will get an error if you later `dup` or `clone` the document:\r\n\r\n```ruby\r\nclass Foo\r\n  include Mongoid::Document\r\n  field :name, :type => String\r\nend\r\n\r\nf = Foo.create\r\nFoo.collection.find({:_id => f.id}).update(:$set => {:old_property => \"value\"})\r\nf.reload()\r\nf.dup\r\n\r\nMongoid::Errors::UnknownAttribute:\r\nProblem:\r\n  Attempted to set a value for 'old_property' which is not allowed on the model Foo.\r\nSummary:\r\n  Without including Mongoid::Attributes::Dynamic in your model and the attribute does not already exist in the attributes hash, attempting to call Foo#old_property= for it is not allowed. This is also triggered by passing the attribute to any method that accepts an attributes hash, and is raised instead of getting a NoMethodError.\r\nResolution:\r\n  You can include Mongoid::Attributes::Dynamic if you expect to be writing values for undefined fields often.\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/bundler/gems/mongoid-4294ce79f6aa/lib/mongoid/attributes/processing.rb:100:in `process_attribute'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/bundler/gems/mongoid-4294ce79f6aa/lib/mongoid/attributes/processing.rb:25:in `block in process_attributes'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/bundler/gems/mongoid-4294ce79f6aa/lib/mongoid/attributes/processing.rb:23:in `each_pair'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/bundler/gems/mongoid-4294ce79f6aa/lib/mongoid/attributes/processing.rb:23:in `process_attributes'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/bundler/gems/mongoid-4294ce79f6aa/lib/mongoid/document.rb:110:in `block in initialize'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/bundler/gems/mongoid-4294ce79f6aa/lib/mongoid/threaded/lifecycle.rb:84:in `_building'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/bundler/gems/mongoid-4294ce79f6aa/lib/mongoid/document.rb:104:in `initialize'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/bundler/gems/mongoid-4294ce79f6aa/lib/mongoid/copyable.rb:25:in `new'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/bundler/gems/mongoid-4294ce79f6aa/lib/mongoid/copyable.rb:25:in `clone'\r\n\tfrom (irb):23\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'\r\n\tfrom /Users/jonathan/.rvm/gems/ruby-2.1.5/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'\r\n\tfrom bin/rails:4:in `require'\r\n\tfrom bin/rails:4:in `<main>'2.1.5 :024 >\r\n```"},"comment":{"url":"https://api.github.com/repos/mongoid/mongoid/issues/comments/99350704","html_url":"https://github.com/mongoid/mongoid/issues/4030#issuecomment-99350704","issue_url":"https://api.github.com/repos/mongoid/mongoid/issues/4030","id":99350704,"user":{"login":"huanzhang","id":3303276,"avatar_url":"https://avatars.githubusercontent.com/u/3303276?v=3","gravatar_id":"","url":"https://api.github.com/users/huanzhang","html_url":"https://github.com/huanzhang","followers_url":"https://api.github.com/users/huanzhang/followers","following_url":"https://api.github.com/users/huanzhang/following{/other_user}","gists_url":"https://api.github.com/users/huanzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/huanzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huanzhang/subscriptions","organizations_url":"https://api.github.com/users/huanzhang/orgs","repos_url":"https://api.github.com/users/huanzhang/repos","events_url":"https://api.github.com/users/huanzhang/events{/privacy}","received_events_url":"https://api.github.com/users/huanzhang/received_events","type":"User","site_admin":false},"created_at":"2015-05-06T07:09:29Z","updated_at":"2015-05-06T07:09:29Z","body":"@jonhyman will 5.0.0 fix this?"}}