# Problemen met het overschrijven van getters in een controller (3.0.0)

**URL:** https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793
**Category:** Bug
**Created:** [14 januari 2023 om 18:57 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793 "2023-01-14T18:57:15Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [14 januari 2023 om 18:57 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/1 "2023-01-14T18:57:15Z")

</div>

I’ve got this code in my initializer, it’s attempting to override the getter for `allAdminRoutes`:

```plaintext
    api.modifyClass('controller:admin-plugins', {
      pluginId: PLUGIN_ID,

      get allAdminRoutes() {
        return this.model
          .filter((p) => p?.enabled)
          .map((p) => {
            return p.admin_route;
          })
          .filter(Boolean);
      },
    });

```

It’s failing with:

`TypeError: this.model is undefined`

Now, I wouldn’t mind, but it’s just [the original getter code](https://github.com/discourse/discourse/blob/782f43cc551e38042392f83a29be970905cb1536/app/assets/javascripts/admin/addon/controllers/admin-plugins.js#L18) (I’ve not actually changed it yet!)

what am I missing? Is overriding a getter in this way somehow not supported or does it introduce some kind of scoping issue?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [16 januari 2023 om 09:45 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/2 "2023-01-16T09:45:02Z")

</div>

Oddly this doesn’t seem to be an issue with Latest. (That was only a test on Production.)

I’ll see if I can reproduce on a clean 3.0.0 Stable.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [16 januari 2023 om 10:38 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/4 "2023-01-16T10:38:28Z")

</div>

The example _should_ work, and I’m not aware of any relevant changes between the stable release and now. Let us know if you manage to reproduce the issue!

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [16 januari 2023 om 10:40 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/5 "2023-01-16T10:40:52Z")

</div>

thanks David. Will do. Yes I noticed that. Ball is definitely in my court for now as the environment in which I experienced this was not fully clean.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [16 januari 2023 om 22:23 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/7 "2023-01-16T22:23:54Z")

</div>

OK David, it appears (and this is weird):

- works in Production
- fails in Development 3.0.0 onwards (possibly before)

- I’ve tested on a vanilla no docker Dev environment but also on a very clean (but possibly config incomplete bespoke Docker dev environment).

Here’s the errors:

```plaintext
Error occurred:

- While rendering:
  -top-level
    application
      discourse-root
        sidebar-wrapper
          admin
            admin-wrapper
              nav-item
                link-to
                  -link-to

```

```plaintext
Uncaught (in promise) TypeError: While generating link to route "adminPlugins": this.model is undefined
    get allAdminRoutes admin-plugins.js:20

```

note that I can put a debugger statement before the `return this.model` and it never fires the debugger.

@RGJ has kindly also looked at this and can repro this result.

This is a bit of a problem as clearly we need to develop stuff before it goes to production … but I don’t have to tell you that! 😅 Also a bit annoying it’s a problem on Stable …

Moved to #Contribute > Bug for now …

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [16 januari 2023 om 22:46 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/8 "2023-01-16T22:46:38Z")

</div>

OK we’re even more sure of there’s an issue here… as mergeMixins is mentioned in the stack trace

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/c/6/7c6d810586ce26c0a74272852156bc2e9bbd03cc.png)

[https://github.com/emberjs/ember.js/issues/18860](https://github.com/emberjs/ember.js/issues/18860)

(thanks to @RGJ for finding this)

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [18 januari 2023 om 17:57 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/10 "2023-01-18T17:57:53Z")

</div>

Nice digging - thanks @merefield and @RGJ

I’m not sure how much we can do to fix this within Discourse - as you noted, the issue seems to be upstream in Ember. Perhaps we can patch the problematic method 🤔

To get us started, I’ve added a minimal failing test case so we can track progress. There are some comments in the test which describe why the issue is being triggered by our `modifyClass` system:

[https://github.com/discourse/discourse/pull/19911](https://github.com/discourse/discourse/pull/19911)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [18 januari 2023 om 17:59 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/11 "2023-01-18T17:59:56Z")

</div>

Yeah, thanks for your efforts too. It’s strange they’ve left that issue unaddressed? Do we know if (Ember) 4.x will resolve it?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [18 januari 2023 om 18:05 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/12 "2023-01-18T18:05:53Z")

</div>

Unfortunately it looks like the issue still exists in Ember 4.x 😢

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [18 januari 2023 om 20:53 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/13 "2023-01-18T20:53:04Z")

</div>

> [@david](#):
>
> added a minimal failing test case

Funnily enough that seems to be the only progress over at the Ember project, within the associated PR which is still in Draft. I wonder if all that would be required is a polite request to prioritise it when the time becomes available?:

[https://github.com/emberjs/ember.js/pull/20129](https://github.com/emberjs/ember.js/pull/20129)

Fully appreciate this was opened by a staff member at a third party.

Is it worth raising an issue over at [GitHub - emberjs/ember.js: Ember.js - A JavaScript framework for creating ambitious web applications · GitHub](https://github.com/emberjs/ember.js) and referencing this PR, this Topic and your test?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [18 januari 2023 om 22:06 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/14 "2023-01-18T22:06:59Z")

</div>

Yep, my test is based on theirs (but with the discourse-specific `api.modifyClass` api). I don’t think we should open a new issue - it’s 100% the same as [the one that’s already open](https://github.com/emberjs/ember.js/issues/18860). We’ll see if we can do anything to get it prioritised.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2 maart 2023 om 11:21 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/15 "2023-03-02T11:21:14Z")

</div>

Making some progress here - we now have a PR with a fix open at [[BUGFIX LTS] Don't run getters while applying mixins by wycats · Pull Request #20388 · emberjs/ember.js · GitHub](https://github.com/emberjs/ember.js/pull/20388)

Once that’s merged and backported to Ember 3.28, we’ll aim to get it applied to Discourse ASAP

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [2 maart 2023 om 14:21 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/16 "2023-03-02T14:21:14Z")

</div>

> [@david](#):
>
> Once that’s merged and backported to Ember 3.28

Backported?! I wondered about that, awesome news!

Thanks for shepherding this one David!

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [5 mei 2023 om 11:59 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/18 "2023-05-05T11:59:01Z")

</div>

This fix has now been released as part of Ember 3.28.12, and we’ve [updated Discourse](https://github.com/discourse/discourse/commit/ca1ee6751f3f2762be106ef9127219c7faf37126) to use it. Please let us know if you’re still seeing any issues with `modifyClass` after updating to the latest Discourse.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [5 mei 2023 om 12:01 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/19 "2023-05-05T12:01:47Z")

</div>

Awesome David, thanks very much!

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [15 mei 2023 om 07:00 UTC](https://meta.discourse.org/t/issues-overriding-getters-in-a-controller-3-0-0/251793/20 "2023-05-15T07:00:58Z")

</div>

This topic was automatically closed after 9 days. New replies are no longer allowed.
