"stack level too deep" error with DataMapper #204

Closed
flexd opened this Issue Nov 29, 2011 · 10 comments

Comments

Projects
None yet
3 participants

flexd commented Nov 29, 2011

get '/' do
  @articles = Article.paginate(:page => params[:page])
  haml :articles
end
get '/articles' do
  @articles = Article.paginate(:page => params[:page], :per_page => 2)
  haml :articles
end

The first example (GET /) works fine, though I do not get any pagination links.

The second example causes a stack level too deep error.

Using gem 'will_paginate', '~> 3.0', :git => 'git://github.com/mislav/will_paginate.git'

require 'will_paginate'
require 'will_paginate/data_mapper'

I really have no idea what's going on here. It was sort of working earlier but now I just get that :s

flexd commented Nov 29, 2011

Actually... specifying :per_page on the GET / route works.. still no pagination but it doesn't crash.. what the hell!

flexd commented Nov 29, 2011

Uh nevermind me.. I seem to be facing a odd haml issue. Moving = will_paginate @articles ABOVE my for-each loop seems to work :/

flexd commented Nov 29, 2011

https://gist.github.com/a12f3f64a249c09eafc9

This might be a combination of a haml and will_paginate error, I can put pretty much anything else in haml under there except will_paginate. Would appreciate if anyone had any ideas!

flexd commented Nov 29, 2011

It would seem whenever i specify the ?page=X it gets that error.

Owner

mislav commented Nov 29, 2011

You should try to reproduce the error outside of Sinatra and Haml. It probably doesn't have to do with any of them.

You should create a script like:

## omgbug.rb
articles = Article.paginate(:page => 1, :per_page => 3)
articles.each { |a| a.title }
# these properties are what `will_paginate` helper accesses in `articles`:
p articles.total_pages
p articles.current_page

Run it with (assuming your main sinatra app is "app.rb"):

ruby -r./app omgbug.rb

Try to reproduce the error. It might be in will_paginate's DataMapper adapter.

flexd commented Nov 29, 2011

I will try to reproduce it outside sinatra and haml but the problem is it seems to be a entirely haml based problem.

But I do not really know that much about things like these so it's probably safe to ignore some of the things I say :-D

if the view looks like this it works perfectly.

= will_paginate @articles
%ul.articles
  - @articles.each do |article|
    %li
      %a{:href=>"/article/#{article.id}"}=article.title

If it looks like this (only difference is that will_paginate is below @articles.each ...) it does not work at all. A stack level too deep error is produced.

%ul.articles
  - @articles.each do |article|
    %li
      %a{:href=>"/article/#{article.id}"}=article.title
= will_paginate @articles

I'm just unsure as to how and why the place where will_paginate is executed matters.

I can put anything like %p Hello world after @articles.each ... without problems. It ONLY results in that error whenever ?page= is set and will_paginate @articles is being run below the for-each.

Running it without sinatra like you said results in:

ruby testing.rb 
DataObjects::URI.new with arguments is deprecated, use a Hash of URI components (/Users/Kristoffer/Developer/.rvm/gems/ruby-head@spillbot/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:231:in `new')
/Users/Kristoffer/Developer/.rvm/rubies/ruby-head/lib/ruby/1.9.1/set.rb:68: stack level too deep (SystemStackError)
Owner

mislav commented Dec 4, 2011

So you ran my script, got the same error ("stack level too deep"), and you still think the exception is related to Haml?

Haml can't really create bugs in your application. It's a mature templating system. It compiles down to a ordinary ruby script at runtime, so any bugs that happen inside your templates are most probably your own (or those of a library you're using, like will_paginate).

Anyway, this is enough information for me, I'll try to see what's going on. Thanks

flexd commented Dec 4, 2011

I don't know if it's related to haml but considering I only get the bug in my code if = will_paginate is at a specific spot it fails I was guessing.

I just changed the title to reflect what's been discovered since the issue had nothing to do with the per_page attribute (seemingly).

Anyway thanks for looking into it. :-)

zolk commented Jan 13, 2012

Looks like I'm running into the same issue with Sinatra 1.3.2, DataMapper 1.2.0, and will_paginate 3.0.2. Using ERB in my case, so it's certainly not a HAML issue.

My route:

get '/' do
    @posts = Post.paginate(:order => :published_at.desc, :page => params[:page], :per_page => 5)
    erb :index
end

As flexd mentioned in an earlier comment, I get the "stack level too deep" error only if I put will_paginate anywhere below the for-each loop in the view.

This works:

<%= will_paginate @posts %>

<% @posts.each do |post| %>
    <%= post.content %>
<% end %>

This gives me "stack level too deep":

<% @posts.each do |post| %>
    <%= post.content %>
<% end %>

<%= will_paginate @posts %>

For what it's worth, I found an unanswered question on StackOverflow where a user is reporting the same problem with Rails 3.1 w/ DataMapper.

@mislav mislav added a commit that referenced this issue Jan 31, 2012

@mislav mislav Data Mapper: fix to_a and association bug
Closes #197, #218, #216, #204
c88edf1
Owner

mislav commented Jan 31, 2012

Thanks for all the data! I've just released 3.0.3, try it out!

mislav closed this Jan 31, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment