# Unexpected error when executing smart actions (V8 + Multiple DBs)

**URL:** <https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894>\
**Category:** Help me!\
**Created:** [December 11, 2021, 7:01pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894 "2021-12-11T19:01:34Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![nivea](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@nivea](https://community.forestadmin.com/u/nivea)\
**Post date:** [December 11, 2021, 7:01pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/1 "2021-12-11T19:01:34Z")

</div>

## Feature(s) impacted

Two days ago I posted a [topic](https://community.forestadmin.com/t/upgrading-to-v7-multiple-nosql-databases/3877) here with some questions I had when including another database in my project. The issue was solved, and later I decided to upgrade the project to V8 since I wanted to take advantage of some features released on _load hook_ and _change hook_. However, all smart actions give me a 500 error when executed.

## Observed behavior

All smart actions show an error like below when executed.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/1/187eae7461c5168947de7f8a513fd2bd3061cc01.png)

I’d like to point out that the _hooks_ execute as expected given that I successfully load some data (coming from the database) to a dropdown field in the smart action form. On the other hand, the _route_ associated with the smart action does not execute, which makes me think the problem happens in-between, maybe?

## Expected behavior

Expected all smart actions to be working properly.

## Failure Logs

This is the result after inspecting the page:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/d/d2b39b41a3ce2abaadfe96d3700c0246b42d6eb4.png)

## Context

- Project name: parceiros
- Environment name: development
- Package Version: 8.0.0 (forest-express-mongoose)
- Engine: nodejs
- Engine Version": 10.24.1

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [December 13, 2021, 8:05am UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/2 "2021-12-13T08:05:12Z")

</div>

Hey @nivea 👋

Could you please share here or as DM:

- The smart action code (With the route definition, defined in `/routes/your_model.js`)
- The Forest action definition (Defined in `/forest/your_model.js`)

Looking at the error, I’m expecting a difference between your smart action name & the route name used.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [December 13, 2021, 1:10pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/3 "2021-12-13T13:10:54Z")

</div>

Thanks, I’ve received the file.  
Could you also check your agent logs to see if any issue appear there?  
And finally, could you send the HTTP request and response that trigger the HTTP 500 ?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![nivea](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@nivea](https://community.forestadmin.com/u/nivea)\
**Post date:** [December 13, 2021, 2:00pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/4 "2021-12-13T14:00:29Z")

</div>

I’m executing the project through docker, so here are the logs presented until I trigger the smart action:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/5/5cfdb97a036abf6636ff95730e182c0f8866f93a.png)

Also, does the failure log I mentioned above correspond to the HTTP request you are asking for?

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [December 13, 2021, 2:03pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/5 "2021-12-13T14:03:44Z")

</div>

It does. I would suggest to wrap your smart action code (The one located in `/routes`) in a try/catch block so you should be able to get more informations of what going on - and why your server is throwing this error 500.

---

<div class="post-metadata">

**Author:** ![nivea](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@nivea](https://community.forestadmin.com/u/nivea)\
**Post date:** [December 13, 2021, 2:19pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/6 "2021-12-13T14:19:30Z")

</div>

I tried doing that, but the problem seems to be that the code in `/routes` is not even triggered. I tested a `console.log()` at the beginning of the function and that was not even printed 😞

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [December 13, 2021, 2:20pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/7 "2021-12-13T14:20:51Z")

</div>

@nivea

Any furthers logs in your chrome browser?  
Any specific CORS configuration that could make this fail?  
Could you also try the same action without the `permissionMiddleware` call, just to check if everything works fine without it ?

---

<div class="post-metadata">

**Author:** ![nivea](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@nivea](https://community.forestadmin.com/u/nivea)\
**Post date:** [December 13, 2021, 2:41pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/8 "2021-12-13T14:41:10Z")

</div>

It worked without the `permissionMiddleware` call.

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [December 13, 2021, 2:44pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/9 "2021-12-13T14:44:19Z")

</div>

Ok, I’m able to reproduce the issue. It seems like there is an issue with `permissionMiddlewareCreator.smartAction(). I’m opening a ticket on our end, so be sure you’ll be pinged once fixed.

---

<div class="post-metadata">

**Author:** ![nivea](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@nivea](https://community.forestadmin.com/u/nivea)\
**Post date:** [December 13, 2021, 2:46pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/10 "2021-12-13T14:46:27Z")

</div>

All right, I appreciate it 🙂

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [December 13, 2021, 3:43pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/11 "2021-12-13T15:43:23Z")

</div>

Hi @nivea 👋 unfortunately my team mate speak a little fast.  
We can’t reproduce. Please can you check if you install the latest version of `forest-express-sequelize`?

```javascript
npm ls forest-express-sequelize
// or
yarn list forest-express-sequelize

```

---

<div class="post-metadata">

**Author:** ![nivea](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@nivea](https://community.forestadmin.com/u/nivea)\
**Post date:** [December 13, 2021, 4:01pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/12 "2021-12-13T16:01:57Z")

</div>

Hey @Arnaud_Moncel

I have not installed this package. After executing the command you suggested, it returns `-- (empty)`.  
I just have `forest-express-mongoose` in my dependencies:

```javascript
"dependencies": {
    "body-parser": "1.19.0",
    "chalk": "~1.1.3",
    "cookie-parser": "1.4.4",
    "cors": "2.8.5",
    "debug": "~4.0.1",
    "dotenv": "~6.1.0",
    "express": "~4.17.1",
    "express-jwt": "6.0.0",
    "forest-express-mongoose": "^8.0.0",
    "mongoose": "~5.8.2",
    "mongoose-bcrypt": "~1.9.0",
    "mongoose-unique-validator": "~2.0.3",
    "morgan": "1.9.1",
    "onesignal-node": "^3.2.1",
    "phone": "^3.1.10",
    "require-all": "^3.0.0"
  }

```

If it is of any help, I’m attaching the errors shown in the Chrome console.

[log\_errors.tar](https://community.forestadmin.com/uploads/short-url/aL3AZOmh0wnMnGDQ2rkwLcZgAHE.tar) (36 KB)

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [December 13, 2021, 4:03pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/13 "2021-12-13T16:03:48Z")

</div>

Oh yeah you use mongoose sorry about that, So what is the result of the same command using `forest-express-mongoose` instead of `fores-express-sequelize` 🙏

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [December 13, 2021, 4:13pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/14 "2021-12-13T16:13:41Z")

</div>

Can you share with us the request `payload` and the `response` of the failing request from your browser network tab please 🙏

---

<div class="post-metadata">

**Author:** ![nivea](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@nivea](https://community.forestadmin.com/u/nivea)\
**Post date:** [December 13, 2021, 4:37pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/15 "2021-12-13T16:37:03Z")

</div>

If I use `forest-express-mongoose`, it just returns `-- forest-express-mongoose@8.0.0`.

The request and response from my browser are below:

- Request Payload  

- Response  
`{"error":"Smart Action: failed to evaluate permissions"}`

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [December 13, 2021, 4:45pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/16 "2021-12-13T16:45:55Z")

</div>

Can you try to update to the latest version which is v8.4.5 and retry ?

---

<div class="post-metadata">

**Author:** ![nivea](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@nivea](https://community.forestadmin.com/u/nivea)\
**Post date:** [December 13, 2021, 6:47pm UTC](https://community.forestadmin.com/t/unexpected-error-when-executing-smart-actions-v8-multiple-dbs/3894/17 "2021-12-13T18:47:55Z")

</div>

@Arnaud_Moncel

Upgrading solved the problem. Thanks a lot 🙏
