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

breeze.savequeuing.js QueueSaveFailedError "Converting Circular Structure"" #36

Open
Eblax opened this issue Mar 3, 2017 · 2 comments

Comments

@Eblax
Copy link

Eblax commented Mar 3, 2017

After getting some errors "Queued save failed: Converting circular structure to JSON" when saving in Breeze I tracked the issue down to the function rememberAddedOriginalValues in breeze.savequeuing.js

My theory is that the circular structure issue happens because the list of Added entities sometimes ends up containing Modified (and other?) entities.

On line ~189 after:

var added = entities ? entities.filter(function (e) { return e.entityAspect.entityState.isAdded(); }) : entities.filter(function (e) { return e.entityAspect.entityState.isAdded(); }) : self.entityManager.getChanges(null, breeze.EntityState.Added);

It looks like the array in added should contain only Added entities, however for some reason it sometimes contains other entries.

To remove these other entities I added this immediately after the previous lines to remove entities with entitystates other than Added:

for(var x = 0; x < added.length; x++) { if(added[x].entityAspect && added[x].entityAspect.entityState.name != breeze.EntityState.Added) { added.splice(x, 1); x--; } }

This at least seems to have sorted my issues.

@pjparra
Copy link

pjparra commented Apr 27, 2017

I am facing this problem too.

I think I have narrowed the source of the problem down to this:

entityManager.getChanges(null, breeze.EntityState.Added)

The entityManager seems to also return Modified entities.

I have used a similar solution to the one provided by @Eblax with great success.
My version of it just adds a condition in the forEach and uses entityState.isAdded() rather than entityState.name:

added.forEach(function (entity) {
    if (entity.entityAspect.entityState.isAdded()) {
        var props = entity.entityType.dataProperties;
        var originalValues = entity.entityAspect.originalValues;
        props.forEach(function (dp) {
            if (dp.isPartOfKey) {
                return;
            }
            originalValues[dp.name] = entity.getProperty(dp.name);
        });
    }
});

I feel like I am doing something wrong to cause this strange behaviour from the EntityManager, but I can't see what it is. My Entities are fetched from a server via EntityManager.query() and start in the Unchanged state.
If I make two successive calls to EntityManager.saveChanges() so as to trigger the special queuing behaviour, the problem arises.

PS: maybe only ducks face this problem 😉

@steveschmitt
Copy link
Member

Fixed in breeze-client 2.0.1. Please see the Release Notes because the usage has changed.

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

3 participants