Save as a new version throws internal server error
Closed this issue · 6 comments
"Save as a new version" triggers an internal server error.
Clicking the "Save as a new version" button results in an internal server error.
This only happens to me when the CMS has been deployed, as the functions behave as expected locally. I am providing the logs that the CMS threw when showing an internal server error. I have the same data and configuration as on the CMS locally. I am not sure what the reason could be for getting the error message "getLatestValueByDB is not a function or its return value is not iterable"
, so perhaps someone here can help me identify the possible causes.
Steps to reproduce the behavior
Can't reproduce locally.
Expected behavior
The plugin is expected to generate a new version upon clicking the "Save as a new version" button.
System
- Node.js version: 17.9.1-alpine
- NPM version: >=6.0.0
- Strapi version: 4.9.0
- Database: Postgres
- Operating system: Linux
Logs
[2023-08-10 17:27:40.167] error: getLatestValueByDB is not a function or its return value is not iterable
TypeError: getLatestValueByDB is not a function or its return value is not iterable
at createVersion (/app/node_modules/@notum-cz/strapi-plugin-content-versioning/server/services/core-api.js:74:28)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.save (/app/node_modules/@notum-cz/strapi-plugin-content-versioning/server/controllers/admin.js:39:12)
at async returnBodyMiddleware (/app/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
at async policiesMiddleware (/app/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
at async /app/node_modules/@strapi/strapi/lib/middlewares/body.js:58:9
at async /app/node_modules/@strapi/strapi/lib/middlewares/powered-by.js:16:5
at async cors (/app/node_modules/@koa/cors/index.js:107:16)
at async /app/node_modules/@strapi/strapi/lib/middlewares/errors.js:13:7
at async /app/node_modules/@strapi/strapi/lib/middlewares/logger.js:9:5
[2023-08-10 17:27:40.168] http: POST /content-versioning/api::ourcontent.ourcontent/save?plugins[i18n][locale]=cs (336 ms) 500
The issue is still happening even after updating to strapi v4.12.0.
It would seem like the issue comes from this file:
The function is declared here:
Hello @ZirixCZ,
are you please able to inspect what is returned as latest
from your database? When PostreSQL is used, the results should be in latest.rows
which the getLatestValueByDB
returns.
I was having the same error and I managed to track it down to the use of the environment variable DATABASE_CLIENT
in node_modules/@notum-cz/strapi-plugin-content-versioning/server/utils/index.js
In my environment variables DATABASE_CLIENT
wasn't set as it doesn't seem to be a requirement for other things to work. This meant that getLatestValueByDB
was returning latest
rather than latest.rows
as it should do for postgres
@craigbloodworth Thank you for the examination. That might definitely be the problem. Since there is env('DATABASE_CLIENT', 'sqlite')
in database.js in Strapi I assumed that it is required to be set if you use any other DB than sqlite.
We will put this in the readme.
@ZirixCZ Could you please check whether this was the problem also for you? If so, we could close this issue.
config/database.ts
export default ({ env }) => ({
connection: {
client: 'postgres',
connection: {
...
Even though we had the above in our config, the enviromental variable DATABASE_CLIENT
was indeed missing. Adding it fixed the issue. Thanks @omikulcik & @craigbloodworth ❤️
it fixes also on version:
- strapi: 4.20.0
- plugin: 1.2.9