datamapper / dm-types

DataMapper plugin providing extra data types
http://datamapper.org/
MIT License
55 stars 80 forks source link

can't modify frozen NilClass #77

Closed tpitale closed 9 years ago

tpitale commented 9 years ago

Calling empty? on an has n association. Ruby 2.2.0, worked previous versions of ruby.

from bundle/ruby/2.2.0/gems/dm-types-1.2.2/lib/dm-types/support/dirty_minder.rb:144:in `track'
from bundle/ruby/2.2.0/gems/dm-types-1.2.2/lib/dm-types/support/dirty_minder.rb:161:in `hook_value'
from bundle/ruby/2.2.0/gems/dm-types-1.2.2/lib/dm-types/support/dirty_minder.rb:151:in `set!'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:607:in `block (2 levels) in load'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:598:in `each'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:598:in `block in load'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:577:in `map'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:577:in `load'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/repository.rb:162:in `read'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/collection.rb:1118:in `lazy_load'
from bundle/ruby/2.2.0/gems/dm-core-1.2.1/lib/dm-core/support/lazy_array.rb:87:in `empty?'
from (irb):2
from bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
from bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
from bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'irb(main):003:0> r.extract_logs.empty?
tpitale commented 9 years ago

Subsequent calls to exactly the same method work. Always fails the first time.

tpitale commented 9 years ago

This may be a dm-core issue, and only happens to manifest through dm-types because of the DirtyMinder module misdirection.

tpitale commented 9 years ago

This appears to be related to https://github.com/datamapper/dm-types/pull/71. Closing.

tpitale commented 9 years ago

Loading a collection at all, for the first time (as empty? evidently does in dm) where one of the properties is Json, Hash, or Array (the classes extended by hooks for dirtiness tracking) leads to this error. No other collection loading fails in this way. Pretty sure that makes it a dm-types issue.

tpitale commented 9 years ago

This is fixed by PR #50. But, despite it saying in the release from github that v1.2.2 https://github.com/datamapper/dm-types/compare/v1.2.2...master has that PR included, looking at the code for the gem release 1.2.2 it does not have the code from PR #50.

robclancy commented 9 years ago

This issue has made me regret use datamapper at all :/

gregory commented 8 years ago

same here. that's bad.

julienma commented 8 years ago

Well, same issue. Had to fork v1.2.2 and cherry pick the 3 commits from #50.

Now, I just have to add this to my Gemfile:

gem 'dm-types',
  :git => 'git://github.com/julienma/dm-types.git',
  :branch => 'gem-v1.2.2-with-frozen-nilclass-fix'
ZeroChaos- commented 8 years ago

kinda looks like this still isn't fixed, is this ever going to be fixed?

2016-06-30T14:17:40.172+0000 ERROR pwnscan#9456: Generic Error: can't
modify frozen NilClass
["/var/lib/gems/2.3.0/gems/dm-types-1.2.2/lib/dm-types/support/dirty_minder.rb:144:in
`track'",
"/var/lib/gems/2.3.0/gems/dm-types-1.2.2/lib/dm-types/support/dirty_minder.rb:161:in
`hook_value'",
"/var/lib/gems/2.3.0/gems/dm-types-1.2.2/lib/dm-types/support/dirty_minder.rb:151:in
`set!'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/resource.rb:880:in
`block in eager_load'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/resource.rb:880:in
`each'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/resource.rb:880:in
`eager_load'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/resource.rb:865:in
`lazy_load'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/property.rb:664:in
`lazy_load'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/resource/persistence_state/persisted.rb:23:in
`lazy_load'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/resource/persistence_state/persisted.rb:8:in
`get'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/model/property.rb:209:in
`attributes_meta'",
"/opt/pwnix/pwnscan/lib/pwnscan/helpers/host_update_helper.rb:21:in
`initialize'",
"/opt/pwnix/pwnscan/lib/pwnscan/models/network_host.rb:252:in `new'",
"/opt/pwnix/pwnscan/lib/pwnscan/models/network_host.rb:252:in
`update_from_parsed_hash'",
"/opt/pwnix/pwnscan/lib/pwnscan/models/network_host.rb:265:in
`mark_offline'",
"/opt/pwnix/pwnscan/lib/pwnscan/models/network_host.rb:97:in `block in
deduplicate'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/collection.rb:508:in
`block in each'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/lazy_array.rb:411:in
`block in each'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/lazy_array.rb:411:in
`each'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/lazy_array.rb:411:in
`each'",
"/var/lib/gems/2.3.0/gems/dm-core-1.2.1/lib/dm-core/collection.rb:505:in
tpitale commented 8 years ago

DM is mostly unmaintained. So, no, probably not getting fixed.

jcran commented 7 years ago

Ran into this as well, accelerated a project's move off datamapper.

joshleblanc commented 7 years ago

This can be avoided by turning off lazy loading for the property.

property :some_json, Json, lazy: false

Obviously, you lose the benefits of lazy loading.