#1235 ✓resolved
Jakub Suder

stack level too deep when creating subrecords in after :save

Reported by Jakub Suder | April 6th, 2010 @ 07:59 AM | in 1.0.0

Given such pair of classes:

class Activity
  include DataMapper::Resource
  property :id, Serial
  property :name, String

  has n, :activity_fields

  after :save do
    self.activity_fields.create :name => 'default field'

class ActivityField
  include DataMapper::Resource
  property :id, Serial
  property :name, String
  property :activity_id, Integer

  belongs_to :activity

calling Activity.create results in an infinite loop. The after save handler in Activity creates an ActivityField, which in turn during its save tries to save its parent (?!). Even though the parent is already saved, the after save handler is apparently called again, which creates the ActivityField again, and so on.

Comments and changes to this ticket

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) April 11th, 2010 @ 10:36 AM

    • Milestone set to 1.0.0
    • State changed from “new” to “resolved”

    Jakub, I tried running your script against latest master branches (in all the separate repositories) and I can't reproduce the error you get. I initially set out to confirm your ticket, because I was seeing similar stack level too deep errors in an app of ours too. They only started to happen after the patch that refactored the persistence layer to use a state machine. However, it looks like this bug here has either been resolved, or wasn't the one I got in the first place.

    Have a look at what I get when running your attached standalone: http://is.gd/bopCG

    I'm marking this resolved for now. Feel free to reopen if you still have problems. For reference, in case you haven't read it on the mailing list, DM repos have been reorganized quite a bit, so for instructions how to get a working setup using all master branches, have a look at: http://is.gd/bopUF

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.

New-ticket Create new ticket

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