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

Underlying object for changeset is missing... #464

Closed
danieljsummers opened this issue Apr 29, 2020 · 18 comments · Fixed by #501
Closed

Underlying object for changeset is missing... #464

danieljsummers opened this issue Apr 29, 2020 · 18 comments · Fixed by #501

Comments

@danieljsummers
Copy link

(...but it's not)

Version

ember-cli: 3.17.0
ember-changeset: 3.3.1
ember-cli-typescript: 3.1.3

Test Case

given: a component that expects a changeset as a property

import { module, test } from 'qunit'
import { setupRenderingTest } from 'ember-qunit'
import { render } from '@ember/test-helpers'
import { hbs } from 'ember-cli-htmlbars'

import Changeset from 'ember-changeset'

module('Integration | Component | my-component', function(hooks) {
  setupRenderingTest(hooks)

  test('it renders', async function(assert) {
    const obj = { bob: 'tom' }
    assert.ok(Boolean(obj), 'This should be true') // <- this, the same assert from the library, passes
    // @ts-ignore
    this.set('changeset', new Changeset(obj)) // <- this bombs with the above error
    // ...remainder of test ellided...
  })
})

(this is in a closed-source project; I can't provide a link to the repo, but I can provide more information if you'd like)

Steps to reproduce

npx ember test

Expected Behavior

The test should continue, and render the component using the changeset.

Actual Behavior

The test fails on the indicated line above, with the error Error: Assertion Failed. Underlying object for changeset is missing.

It may be significant (or not) that the result is the same whether the file ends with .js or .ts; this doesn't appear (to me) to be an Ember TypeScript edge case.

@snewcomer
Copy link
Collaborator

👋 Can you try the function approach? I don't think it should matter so I'm a bit confused atm.

import { Changeset } from 'ember-changeset';

... = Changeset(obj)

@danieljsummers
Copy link
Author

Sadly, same result...

@danieljsummers
Copy link
Author

On a lark, I decided to blow away node_modules and refresh it; the result was still the same.

@danieljsummers
Copy link
Author

I don't have ember-cli installed globally, so I'm running it with npx ember test - should that matter?

@snewcomer
Copy link
Collaborator

Do you have a minimal repo that I could test with?

@danieljsummers
Copy link
Author

I'll let you know when I have it ready.

@michael-lowe-nz
Copy link

michael-lowe-nz commented May 9, 2020

I'm also having this issue:

meals.hbs

{{#with (changeset model.meals (action this.validateMeal)) as |changesetObj|}}
  <form {{on "submit" (fn this.addMeal changesetObj)}}>
    <Input @value={{changesetObj.name}} class="input" placeholder="Name" />
  </form>
{{/with}}

controller.js

export default class MealsController extends Controller {
    @action
    addMeal (changeset) {
        event.preventDefault();
        const newMeal = this.store.createRecord('meal', {
            name: changeset.name,
        });
        changeset.save();
    }

When calling the addMeal function, I get:
list.js:20 Uncaught TypeError: changeset.save is not a function

I feel like this may be the same underlying cause, but I'm not sure.

Ember : 3.18.1
Ember Data : 3.18.0
ember-changeset: 3.3.4

@snewcomer
Copy link
Collaborator

@michael-lowe-nz Looks like we have tests somewhat close to this exact scenario.

  1. What is changeset when it is about to save? Seems like it is not undefined.
  2. What does validateMeal look like?
  3. Is model.meals an array?

A minimally reproducible application would be useful as well!

@michael-lowe-nz
Copy link

michael-lowe-nz commented May 10, 2020

I may make a minimally reproducible application, but what I don't quite understand is about what the model should be when creating a new instance of a hasMany on a model.
At the moment, I am passing the hasMany to the changeset helper. Is this what I should be doing? Or am I missing something here?

  1. changeset before save is this when I log it to the console:
Promise {<resolved>: Proxy, name: "New Meal to add"}
name: "New Meal to add"
__proto__: Promise
catch: ƒ catch()
constructor: ƒ Promise()
finally: ƒ finally()
then: ƒ then()
Symbol(Symbol.toStringTag): "Promise"
__proto__: Object
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: Proxy
  1. Validate Meal
    Nothing special going on here, I can't actually get it to run
@action
export default class ListController extends Controller {
    validateMeal(val) {
        console.log('val', val);
    }
}
  1. model.meals is an array, as in:
    routes.js
export default class ListRoute extends Route.extend(RealtimeRouteMixin, PerformanceRouteMixin) {
    model(params) {
        return this.store.findRecord('list', params.list_id);
    }
}

model/list.js

import Model, { attr, hasMany } from '@ember-data/model';
export default class ListModel extends Model {
    @attr('string') name;
    @hasMany('meal') meals;
}

template.js

{{#with (changeset model.meals (action this.validateMeal)) as |changesetObj|}}
  <form {{on "submit" (fn this.addMeal changesetObj)}}>
      <label>Meal Name</label>
      <Input @value={{changesetObj.name}} class="input" placeholder="Name" />
  </form>
{{/with}}

Hopefully this makes sense, otherwise in what form would I make minimally reproducible application?

@danieljsummers
Copy link
Author

I haven't forgotten about this; it'll likely be early next week.

@snewcomer
Copy link
Collaborator

snewcomer commented May 13, 2020

https://github.com/poteto/ember-changeset/commits/master

I'm seeing some strange behaviour with CI (all ember-try scenarios passing locally). I'm not sure what has changed since our last commit to master 9 days ago (which was ✅). If you have some insight with respect to what you are seeing, would love to hear it and if it might be related!

#472
https://travis-ci.org/github/poteto/ember-changeset/jobs/686404239

@snewcomer
Copy link
Collaborator

Does anybody have a local reproduction with the latest 3.4.0?

@ianknauer
Copy link

@snewcomer i'm seeing this issue with 3.4.1

@snewcomer
Copy link
Collaborator

snewcomer commented Jun 5, 2020

Does anybody have a local reproduction we can all try? Even an ember-twiddle? Perhaps there is a silent error?

@ianknauer
Copy link

@snewcomer i'll try to pull enough out for a reproduction copy this weekend. For me it's happening when i try transitioning to a different route. I Can interact with it no problem up to that point.

@snewcomer
Copy link
Collaborator

Ohhh. Ok that is great information. I have been hitting this with helpers (not changeset) in the apps I work on during/after a route transition.

@ianknauer
Copy link

@snewcomer, i tested your PR against our app and it solved the problem we were having 👍

@danieljsummers
Copy link
Author

danieljsummers commented Jun 5, 2020 via email

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

Successfully merging a pull request may close this issue.

4 participants