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

hasMany relationship broken with [email protected] #281

Closed
sarjanen opened this issue Jan 29, 2018 · 32 comments
Closed

hasMany relationship broken with [email protected] #281

sarjanen opened this issue Jan 29, 2018 · 32 comments

Comments

@sarjanen
Copy link

Upgraded ember-changeset and ember-changeset-validations to the latests versions (1.4.2-beta.0 and 1.2.10) and now every time i access a hasMany relationship i get this weird error:

"Error: Assertion Failed: content must be present.…(http://localhost:4200/assets/vendor.js:39848:18)"

and also this:

Uncaught Error: a glimmer transaction was begun, but one already exists. You may have a nested transaction
    at debugAssert (util.js:62)
    at Environment.begin (runtime.js:6380)
    at Environment.begin (environment.js:252)
    at InteractiveRenderer._renderRoots (renderer.js:270)
    at InteractiveRenderer._renderRootsTransaction (renderer.js:323)
    at InteractiveRenderer._revalidate (renderer.js:360)
    at invoke (backburner.js:258)
    at Queue.flush (backburner.js:151)
    at DeferredActionQueues.flush (backburner.js:329)
    at Backburner.end (backburner.js:462)

Line 39848 in my vendor.js is https://github.com/emberjs/ember.js/blob/bdc2c3e3a15d13d8bb1951d44b1a28ee1c6a36cb/packages/ember-metal/lib/property_get.js#L67

After downgraded ember-changeset-validations to 1.2.8 again everything works. I only get this error when my model that has a hasMany relationship is new and unsaved.

@jelhan
Copy link
Contributor

jelhan commented Feb 2, 2018

It's not related to ember-changeset-validations. Bug was introduced by [email protected]. Here is a simple reproduction: https://ember-twiddle.com/31dad57760c42a665442764c5b96e0f5?fileTreeShown=false&openFiles=twiddle.json%2C

@mukk85
Copy link

mukk85 commented Feb 26, 2018

Any workarounds for this?

@nucleartide
Copy link
Contributor

@mukk85 workaround is to use a non-beta release for now, sadly. I would also appreciate any pull requests addressing this bug!

@mukk85
Copy link

mukk85 commented Feb 26, 2018

I tried to downgrade to ember-changeset-validations 1.2.9 and it was still occuring. Which version would you recommend?

@nucleartide
Copy link
Contributor

@mukk85 The latest version of e-c-v has a more lax version req.

@nucleartide
Copy link
Contributor

Oh sorry, I must have rolled that change back because of an installation issue. Will have to investigate that later.

@jelhan
Copy link
Contributor

jelhan commented Feb 26, 2018

If using yarn, you could enfore a specific version even for sub-dependencies using resolutions key in your package.json. Feature is called Selective dependency resolutions
. You could use that one to enforce [email protected] even if ember-changeset-validations requests [email protected].

@mukk85
Copy link

mukk85 commented Feb 27, 2018

Thanks @jelhan. That is a good temporary solution!

@jordpo
Copy link

jordpo commented Mar 13, 2018

👍 on the temp solution via package.json's resolutions. As a note, you have to have the latest version of Yarn to take advantage of it.

@snewcomer
Copy link
Collaborator

@Padchi @jordpo @mukk85 Would you mind seeing if this error still persists with the latest master? Putting together a 1.5 tracking release issue as well and want to know if I should include this issue in there.

@snewcomer snewcomer mentioned this issue Jul 6, 2018
8 tasks
@snewcomer
Copy link
Collaborator

This is fixed in ember-changeset. Verified by adding, saving, and removing a has many relationship. Will look to releasing 1.5 proper soon!

Lmk if anybody has another issue! Will close for now if you don't mind!

@m-nagy
Copy link

m-nagy commented Aug 29, 2018

I still have the same issue after upgrading to changeset ^1.5.0 and changeset validation ^1.3.0

@snewcomer
Copy link
Collaborator

@m-nagy Would you mind posting a reproduction or example code so we can help? I've tested both belongsTo and hasMany relationships in my own apps.

@snewcomer
Copy link
Collaborator

Also added a m2m test to verify it works. So we might be missing a different scenario.

@lukaiser
Copy link

lukaiser commented Sep 7, 2018

@snewcomer: I have the same problem.
If you update @jelhan twiddle to the newest version it doesn't work either: https://ember-twiddle.com/1b34e71c35c1091fe11ff34f12636fe7

Have you tested it with a template? The tests are all with out one if I am correct. Maybe it has something to do with the glimmer getter.

@snewcomer snewcomer reopened this Sep 7, 2018
@snewcomer
Copy link
Collaborator

Sadly I haven't used it this way in my apps but I am sure you are right wrt to the getter.

Alright, well time to re-evaluate this Relay thing. Requiring .get is not feasible for the new modern Ember. I'm sorry everyone. Perhaps was a good idea while it lasted. Will try to evaluate removing Relay/using plain Proxy (w/ polyfill) for now...

@snewcomer
Copy link
Collaborator

There will be downsides to not using a Relay, but we will see where we can get to support nested objects.

@snewcomer snewcomer mentioned this issue Sep 11, 2018
@hoIIer
Copy link

hoIIer commented Sep 28, 2018

Just upgraded to latest and my acceptance tests are breaking with this error:

Exam Partition 1 - Acceptance | Admin User Profile Account: User can navigate to a profile page where displayed information is uneditable
    ---
        actual: >
            null
        stack: >
            http://localhost:7357/assets/vendor.js:30088
        message: >
            Uncaught Error: Assertion Failed: content must be present.
        negative: >
            false
        Log: |

@GCorbel
Copy link

GCorbel commented Oct 20, 2018

I have the same issue with this mocha test :

import { expect } from 'chai';
import { setupRenderingTest } from 'ember-mocha';
import { describe, it } from 'mocha';
import Changeset from 'ember-changeset';

describe('Integration | Utils | Changeset', function() {
  setupRenderingTest();

  it('works as a normal changeset', async function() {
    const store = this.owner.lookup('service:store')
    const form = store.createRecord('form');
    const changesetForm = new Changeset(form);
    expect(changesetForm.get('fields.length')).to.eq(0);
  });
});

In this case, a form has many fields. I checked a bit and it happens because, Ember.isPresent(form.fields) gives false if the array is empty. So adding form.fields.pushObject(field) works.

I think the the code should check if it's an array before to show the error.

@GCorbel
Copy link

GCorbel commented Oct 20, 2018

Also, it seems than changesetForm.get('fields') doesn't work. I have this message : "You attempted to access the length property (of <(unknown):ember192>).".

@lougreenwood
Copy link

I'm also getting this, have downgraded back to EC 1.3.0 to resolve

@abobwhite
Copy link

I'm seeing something along these lines with the latest EC (1.6.0). I have an embedded records mixin record with embedded: 'always' on a hasMany relationship and when I try to access that relationship, I am getting a Proxy instead of the actual content.

@snewcomer
Copy link
Collaborator

@abobwhite Do you have an example that you could share (even psuedo code)? Working on 2.0-beta branch (try if out if you would like - it might fix your issue) and would like to add a test to ensure this isn't present when we release 2.0!

@abobwhite
Copy link

abobwhite commented Jan 1, 2019

@snewcomer Thanks! The issue is not that of the original thread but it is similar to when @GCorbel mentioned on 10/20/18. I have a changeset build on a model tag-group which @hasMany('tag') tags. Here is my tag-group serializer:

class TagGroupSerializer extends ApplicationSerializer {
  attrs = {
    tags: {embedded: 'always'}
  }
}

My snippet of code is trying to iterate over the selected tags via the changeset (I'm using any here but I've confirmed other array functions do the same thing). I had to break apart getting the changeset from the Component and then the tags off of the changeset to get this far. If I use this.get('changeset.tags') then it complains about the any function since the object is a Proxy.

@computed('[email protected]', '[email protected]')
  get remainingTagOptions() {
    return get(this, 'tagOptions').filter((tag) => {
      const changeset = this.get('changeset');
      const tags = changeset.get('tags') || [];
      // NOTE: The line below is where I see the error.
      return !tags.any((selectedTag) => tag.get('name') === selectedTag.get('name'));
    });
  }

It's an issue grabbing the length property when iterating the tags.

"Assertion Failed: You attempted to access the `length` property (of <(unknown):ember651>).
Since Ember 3.1, this is usually fine as you no longer need to use `.get()`
to access computed properties. However, in this case, the object in question
is a special kind of Ember object (a proxy). Therefore, it is still necessary
to use `.get('length')` in this case.

If you encountered this error because of third-party code that you don't control,
there is more information at https://github.com/emberjs/ember.js/issues/16148, and
you can help us improve this error message by telling us more about what happened in
this situation."

I see the same error when using the 2.0-beta branch.

@abobwhite
Copy link

After more searching and debugging, it appears it was actually an error during render of the power-select-multiple and not actually related to EC at all. Sorry for any confusion.

@abobwhite
Copy link

@snewcomer Sorry for the back-and-forth. After even more debugging, I'm no longer sure that it's not EC. I can use the power-select-multiple component with no issues with the same setup using regular ember objects and arrays. But when used with the changeset values, I am seeing the issue.

The above code is not where the error happens but rather during render so it's really hard to figure out where it's happening.

Any thoughts?

@snewcomer
Copy link
Collaborator

@abobwhite Is it specifically const tags = changeset.get('tags') || [];? What happens if you try changeset.get('_content.tags')? That isn't a solution but just curious if you still get an error. Or is it the computed cache breaking key [email protected]?

@abobwhite
Copy link

@snewcomer yes.

It doesn't appear to be the body of the function causing the issue but fwiw, _content.tags didn't work, either, however @computed('tagOptions', 'changeset.tags') helped the situation and also binding in the template to changeset.tags.content did too (I am binding that to the select's selected property and the computed remainingTagOptions to the options property. I am no longer getting that same error, but also my selected binding isn't working (it's not capturing my selected tags correctly). There is some combination of things here that is making it difficult to pinpoint. Somewhere at the intersection of ember-changeset, ember-decorators, and power-select-multiple. I am seeing the issue after upgrading to 3.6 from 2.18.x. Fortunately most things work but anything binding a changeset is not working.

@snewcomer
Copy link
Collaborator

Just to notify everyone, 2.0.0-beta.0 has been published for ember-changeset and ember-changeset-validations. Give it a shot! @abobwhite

@barryofguilder
Copy link

@snewcomer There were two forms in my Ember 3.4 app that had this issue when upgrading from ember-changeset 1.3.0 to 1.5.0 . After upgrading to the new beta versions, I no longer have failing tests for those forms and everything seems to be working! I'll continue to test this out.

Thanks for all the hard work getting this released!

@abobwhite
Copy link

I finally got around to upgrading to 2.0.0, @snewcomer and it appears to be working correctly for me now 🎆 🥂

@snewcomer
Copy link
Collaborator

Thank you everyone. Feel free to reopen if you have any issues!

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

No branches or pull requests