"Maximum call stack size exceeded" on set and deleteRecord in one to one relationship. #732

Closed
Baael opened this Issue Feb 13, 2013 · 17 comments
@Baael

When using RESTadapter in one to one relationship:

App.Post = DS.Model.extend
  author:   DS.belongsTo('App.Author')

App.Author = DS.Model.extend
  post:      DS.belongsTo('App.Post')

author = App.Author.find(1) 
post = author.get('post')

post and author are valid objects

post.deleteRecord()

or

author.set('post',null)

returns: RangeError: Maximum call stack size exceeded

suspect:
https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/model/model.js#L135
:)

Trying to fix and provide tests, however for now I wasn't able to find it in issues, also newest revision of ember-data has same problem.

@codegoblin

+1 this

Stacktrace:

Uncaught RangeError: Maximum call stack size exceeded
DS.Model.reopenClass.eachRelationship
DS.Serializer.Ember.Object.extend.eachEmbeddedRelationship
DS.Serializer.Ember.Object.extend.eachEmbeddedBelongsTo
DS.Serializer.Ember.Object.extend.eachEmbeddedBelongsToRecord
DS.Serializer.Ember.Object.extend.eachEmbeddedRecord
DS.RESTAdapter.DS.Adapter.extend.dirtyRecordsForRecordChange
superWrapper
(anonymous function)
(anonymous function)
(anonymous function)
(anonymous function)
(anonymous function)
OrderedSet.forEach
Map.forEach
DS.Model.reopenClass.eachRelationship
DS.Serializer.Ember.Object.extend.eachEmbeddedRelationship
DS.Serializer.Ember.Object.extend.eachEmbeddedBelongsTo
DS.Serializer.Ember.Object.extend.eachEmbeddedBelongsToRecord
DS.Serializer.Ember.Object.extend.eachEmbeddedRecord
DS.RESTAdapter.DS.Adapter.extend.dirtyRecordsForRecordChange
superWrapper
DS.RESTAdapter.DS.Adapter.extend.dirtyRecordsForRecordChange
superWrapper
(anonymous function)
(anonymous function)
(anonymous function)
(anonymous function)
(anonymous function)
OrderedSet.forEach
Map.forEach
DS.Model.reopenClass.eachRelationship
DS.Serializer.Ember.Object.extend.eachEmbeddedRelationship
DS.Serializer.Ember.Object.extend.eachEmbeddedBelongsTo
DS.Serializer.Ember.Object.extend.eachEmbeddedBelongsToRecord
DS.Serializer.Ember.Object.extend.eachEmbeddedRecord
DS.RESTAdapter.DS.Adapter.extend.dirtyRecordsForRecordChange
superWrapper
DS.Adapter.Ember.Object.extend.dirtyRecordsForBelongsToChange
DS.Store.Ember.Object.extend.recordBelongsToDidChange
DS.RelationshipChange.callChangeEvents

then the following over and over:

set
DS.RelationshipChangeRemove.sync
DS.Model.reopen.belongsToWillChange
sendEvent
Ember.notifyBeforeObservers
propertyWillChange
ComputedPropertyPrototype.set

@ulisesrmzroche

There's an infinite loop in belongsToWillChange. I think the bug is closer to here. https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/relationships/belongs_to.js#L43-L72

@lulezi

I'm also experiencing this issue. Here's a part of the infinitely repeated error stack.

…
sendEvent
Ember.Array.Ember.Mixin.create.arrayContentDidChange
Ember.ArrayController.Ember.ArrayProxy.extend.arrayContentDidChange
superWrapper
Ember.ArrayProxy.Ember.Object.extend.arrangedContentArrayDidChange
sendEvent
Ember.Array.Ember.Mixin.create.arrayContentDidChange
Ember.ArrayController.Ember.ArrayProxy.extend.arrayContentDidChange
superWrapper
Ember.ArrayProxy.Ember.Object.extend.arrangedContentArrayDidChange
sendEvent
…

UPDATE: Note: I'm only experiencing this by accessing the site directly or after a reload and not by routing to it i.e. from the home page.

@giorgosera

+1

I am experiencing this when I try to deleteRecord().

@igorT
Ember.js member

A failing test would be super useful.

@faun

Here's the jsfiddle @cookrn and I came up with to try to reproduce this: http://jsfiddle.net/emTCW/37/. We were using the fixture adapter and this could be modified to use the REST adapter to reproduce this. Can anyone verify this?

@sly7-7

@faun I'm sorry, but I don't see the stacktrace when executing your example :(

@cookrn

Whoops! Same here. I think there's just a misunderstanding on our part for how to specify the fixture data.

In order to finish creating a failing test case w/ this fiddle, a couple of questions:

  • The post, when fetched via the author, is currently null (as seen on L8 of the fiddle). Do the foreign keys need to be specified on both sides for one-to-one belongsTo relationships? See #475

  • Is it even worth exploring whether this can be replicated via the FixtureAdapter? Or should we jump right to the RESTAdapter?

Edit: Updated fiddle here

@sly7-7

@cookrn The problem is that with the fixture adapter (which use the JSONserializer, not the RESTserializer, the foreign key should not be xxx_id, but just xxx. see http://jsfiddle.net/Sly7/emTCW/40/

@cookrn

Thanks @sly7-7 -- seems like unable to reproduce w/ FixtureAdapter w/ either of the described calls per this fiddle.

Confirm?

Next would be to try the RestAdapter

@faun
@sly7-7

@faun @cookrn Do you think this issue can be closed now ? Obviously if you can reproduce it with the RESTAdapter, we will reopen.

@faun
@cookrn

Maybe @Baael @codegoblin @lulezi @giorgosera could weigh in w/ more data about their scenarios? Happy to keep building a failing example w/ more data...

@Baael

Actually, first approach was made with FixtureAdapter and works nicely, later when we implemented REST, to work on real data, problem occoured. After some hooks we made it to work with many to many :) However, after change a lot of logic and data flow.

I will prepare fiddle and test this bug again, ASAP :)

@wagenet
Ember.js member

@Baael any luck on a fiddle for this?

@wycats
Ember.js member

I'm assuming this is moot unless additional information is provided.

@wycats wycats closed this Sep 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment