
Stack level too deep with dm-timestamps and has n/belongs_to relationship
Reported by Sindre Aarsaether | October 14th, 2009 @ 11:53 AM | in 0.10.2
See example: Only happens with dm-timestamps required (even when
it is not used!)
On ruby 1.9.1 p-243. Worked before I updated to latest dm-version
(a week ago or so).
require 'rubygems'
require 'dm-core'
require 'dm-timestamps'
DataMapper.setup(:default, 'mysql://localhost/dm_core_test')
DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, :debug)
class Phone
include DataMapper::Resource
property :id, Serial
property :nr, String
belongs_to :company
end
class Company
include DataMapper::Resource
property :id, Serial
property :name, String
belongs_to :main_phone, :model => Phone, :nullable => true
has n, :phones
end
DataMapper.auto_migrate!
c = Company.create :name => 'Whole Foods'
c.main_phone = c.phones.new :nr => "123"
c.save
# => /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/assertions.rb:4:in `each': stack level too deep (SystemStackError)
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/assertions.rb:4:in `assert_kind_of'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/associations/relationship.rb:320:in `loaded?'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:757:in `block in parent_relationships'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:756:in `each_value'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:756:in `parent_relationships'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:794:in `parent_resources'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:594:in `dirty_parents?'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:595:in `block in dirty_parents?'
# ... 6011 levels...
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:884:in `all?'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:884:in `save_children'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:338:in `save'
# ONLY FAILS if you require dm-timestamps
Comments and changes to this ticket
-
Jonathan Stott (namelessjon) October 14th, 2009 @ 06:45 PM
- State changed from unconfirmed to confirmed
According to git bisect, the problem commit is in dm-core (there are no dm-timestamp changes in the time period):
6b9ab6d A dirty sibling should not make a resource dirty
Attached is the script used to run the bisection.
-
mpd October 14th, 2009 @ 11:22 PM
I believe this is what's causing the issue in #1077 as well. I never make the dm-timestamps connection, though, which is why I was never able to come up with a toy script to repeat it.
Awesome work finding this one!
-
Sindre Aarsaether October 15th, 2009 @ 12:14 AM
Yeah I actually spent atleast 2.5 hours trying to locate the bug. Just found it after I moved all my big models out into a separate script and started removing everything I could. Guess I will do that a lot sooner the next time!
-
Dan Kubb (dkubb) October 22nd, 2009 @ 09:26 PM
- State changed from confirmed to resolved
(from [d4ec6c90871f47bddd0cef3e6ba43b32c1117d62]) Fixed stack-too deep error thrown by saving a circular reference
- This solution involves tracking which resources have been saved in a specific session, and not resaving them. This will require further refactoring since I would like to remove the "resources" shared state and perhaps track if an object is saved in an ivar.
[#1094 state:resolved] http://github.com/datamapper/dm-core/commit/d4ec6c90871f47bddd0cef3...
-
-
Sindre Aarsaether October 25th, 2009 @ 07:03 AM
Just a heads up, I'm still experiencing very similar stack-level too deep problems, even though it might be a different bug.
/usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/assertions.rb:4:in
each': stack level too deep (SystemStackError)
from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/assertions.rb:4:in `assert_kind_of' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/associations/relationship.rb:306:in `loaded?' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:805:in `block in parent_relationships' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:804:in `each_value' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:804:in `parent_relationships' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:841:in `parent_resources' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:618:in `dirty_parents?' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:619:in `block in dirty_parents?' ... 5945 levels... from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/thor-0.9.9/lib/thor.rb:90:in `start' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/thor-0.9.9/bin/thor:7:in `<top (required)>' from /usr/local/ruby/bin/thor:19:in `load' from /usr/local/ruby/bin/thor:19:in `<main>'
/usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/assertions.rb:4:in
each': stack level too deep (SystemStackError)
from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/assertions.rb:4:in `assert_kind_of' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/associations/relationship.rb:306:in `loaded?' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:805:in `block in parent_relationships' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:804:in `each_value' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:804:in `parent_relationships' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:841:in `parent_resources' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:618:in `dirty_parents?' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:619:in `block in dirty_parents?' ... 5945 levels... from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/thor-0.9.9/lib/thor.rb:90:in `start' from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/thor-0.9.9/bin/thor:7:in `<top (required)>' from /usr/local/ruby/bin/thor:19:in `load' from /usr/local/ruby/bin/thor:19:in `<main>'
Will try to reduce it.
-
Sindre Aarsaether October 25th, 2009 @ 07:30 AM
I'm having a hard time reducing it, as it happens in a complex environment. But, it is easy to show that it is definately a bug, and most likely linked to the fix of this one.
invoice = company.invoices.first(*some criteria*) payment.reload # I have a saved payment, just reloading to be certain # THIS THROWS STACK LEVEL TOO DEEP payment.update :invoice => invoice # WHILE THIS DOES NOT payment.invoice = invoice payment.save
So I am guessing that this is really the existing bug, where the fix did not take #update into account somehow?
-
Dan Kubb (dkubb) October 25th, 2009 @ 04:51 PM
- State changed from resolved to unconfirmed
Interesting. Sometimes it helps to attach the whole stacktrace to the ticket, not just the abbreviated version that ruby outputs when it throws a SystemStackError exception.
-
Dan Kubb (dkubb) October 26th, 2009 @ 05:51 AM
- Assigned user set to Dan Kubb (dkubb)
mpd: I just pushed some fixes for a recursion bug I found in another ticket. Can you try updating to edge (git) dm-core and see if it resolves your issue?
-
mpd October 26th, 2009 @ 11:45 AM
I can confirm that my issue (stack too deep/coredumps on freebsd) is resolved on all platforms I have access to.
thanks!
-
Dan Kubb (dkubb) October 26th, 2009 @ 04:30 PM
- Milestone set to 0.10.2
- State changed from unconfirmed to resolved
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Referenced by
-
1094 Stack level too deep with dm-timestamps and has n/belongs_to relationship [#1094 state:resolved] http://github.com/datamapper/dm-c...