Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

praxis-mapper + activesupport 4.x do not play well together with Time #27

Open
stevecrozz opened this issue Mar 10, 2017 · 2 comments
Open

Comments

@stevecrozz
Copy link

Praxis mapper defines data accessors that freeze underlying data objects:
https://github.com/praxis/praxis-mapper/blob/c391302b8ed7637fa40af9492868d19b913b81d3/lib/praxis-mapper/model.rb

But activesupport 4.x foolishly defines a to_time method that mutates Time objects:
https://github.com/rails/rails/blob/v4.2.8/activesupport/lib/active_support/core_ext/date_and_time/compatibility.rb#L19-L25

This effectively prevents us from rendering models that have times and in our application logs we get:

2017-03-10 10:08:39 -0800: [] [ERROR] [WORKER] SAVE_TO_CACHE (failed) Account: 7954, Error: Attributor::DumpError: Error while dumping attribute last_volume_attachment of type V2::MediaTypes::Volume for context volume-F69NQB79UM6HV. Reason: can't modify frozen Time, Cause: can't modify frozen Time
2017-03-10 10:08:39 -0800: [] [ERROR] [WORKER] SAVE_TO_CACHE (failed) Backtrace:
/home/stevecrozz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/praxis-blueprints-3.3/lib/praxis-blueprints/renderer.rb:79:in `rescue in block (2 levels) in _render'
/home/stevecrozz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/praxis-blueprints-3.3/lib/praxis-blueprints/renderer.rb:76:in `block (2 levels) in _render'
/home/stevecrozz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/praxis-blueprints-3.3/lib/praxis-blueprints/renderer.rb:75:in `each'
/home/stevecrozz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/praxis-blueprints-3.3/lib/praxis-blueprints/renderer.rb:75:in `each_with_object'
/home/stevecrozz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/praxis-blueprints-3.3/lib/praxis-blueprints/renderer.rb:75:in `block in _render'
/home/stevecrozz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.8/lib/active_support/notifications.rb:166:in `instrument'
/home/stevecrozz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/praxis-blueprints-3.3/lib/praxis-blueprints/renderer.rb:74:in `_render'
/home/stevecrozz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/praxis-blueprints-3.3/lib/praxis-blueprints/renderer.rb:50:in `render'
/home/stevecrozz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/praxis-blueprints-3.3/lib/praxis-blueprints/view.rb:35:in `render'
/home/stevecrozz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/praxis-blueprints-3.3/lib/praxis-blueprints/blueprint.rb:307:in `render'
/home/stevecrozz/Projects/rs/account_overview/app/v2/modules/big_brother_stat_calculator.rb:550:in `rescue in block in render_resources'
...

I dug into this for a while and ended up upgrading to activesupport 5.x which doesn't have this problem. I'm not sure on the right fix or even if praxis-mapper has a problem. IMO this is more of an activesupport 4.x problem, but since that's such a popular library and already superceded by 5.x, it seems unlikely that it can be fixed in activesupport.

@careo
Copy link
Contributor

careo commented Mar 10, 2017 via email

@blanquer
Copy link
Contributor

well...one reason is probably to respect the "not loaded" flagging:

def #{name}
@__#{name} ||= @data.fetch(#{name.inspect}) do
raise "field #{name.inspect} not loaded for #{self.inspect}."
end.freeze

... as if the accessor is modified, then our code catching that will go away.

If necessary (and I agree that "might" not be at this point) we could make the freezing optional. Even if it was triggered by a simple Constant ("ehem") variable so one could choose setting it to false, if it is absolutely necessary to use the 4.x series.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants