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

TypeError: 123 is not a string when using options[:last] with group_by_duration #233

Closed
tallytarik opened this issue Mar 2, 2020 · 2 comments

Comments

@tallytarik
Copy link

First off, thanks for an amazing gem, and even more thanks for your work on group_by_duration - it's just what I needed for a project of mine!

I've come across an issue - if you try to use last: with group_by_duration, the following error is thrown:

TypeError: <number> is not a symbol nor a string

[..]/groupdate/lib/groupdate/series_builder.rb:154:in `respond_to?'
[..]/groupdate/lib/groupdate/series_builder.rb:154:in `time_range'
[..]/groupdate/lib/groupdate/magic.rb:74:in `time_range'
[..]/groupdate/lib/groupdate/magic.rb:175:in `generate_relation'
[..]/groupdate/lib/groupdate/query_methods.rb:20:in `group_by_duration'
[..]/groupdate/lib/groupdate/enumerable.rb:33:in `block in group_by_duration'
[..]/gems/activerecord-6.0.2.1/lib/active_record/relation.rb:398:in `block in scoping'
[..]/gems/activerecord-6.0.2.1/lib/active_record/relation.rb:773:in `_scoping'
[..]/gems/activerecord-6.0.2.1/lib/active_record/relation.rb:398:in `scoping'
[..]/gems/activerecord-6.0.2.1/lib/active_record/associations/collection_proxy.rb:1101:in `scoping'
[..]/groupdate/lib/groupdate/enumerable.rb:33:in `group_by_duration'

Using, e.g. the following code:

MyModel
  .group_by_duration(15.minutes, :created_at, last: 24, default_value: 0)

The problem is that time_range doesn't check if the period is an Integer (as is the case when grouping by duration) when options[:last] is provided.

Some code was added to handle this case in generate_series. Adding the same code to time_range solves the problem. PR coming.

@ankane
Copy link
Owner

ankane commented Mar 2, 2020

Fixed in #234

@ankane ankane closed this as completed Mar 2, 2020
@ankane
Copy link
Owner

ankane commented Jul 23, 2020

Just fyi, decided to go a different direction to group by 15 minute intervals. See #23 (comment).

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

2 participants