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

Save as a new version throws internal server error #113

Closed
ZirixCZ opened this issue Aug 10, 2023 · 6 comments
Closed

Save as a new version throws internal server error #113

ZirixCZ opened this issue Aug 10, 2023 · 6 comments
Labels
Issue: help wanted Looking for someone to tackle this issue

Comments

@ZirixCZ
Copy link

ZirixCZ commented Aug 10, 2023

"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

@ZirixCZ
Copy link
Author

ZirixCZ commented Aug 11, 2023

The issue is still happening even after updating to strapi v4.12.0.

It would seem like the issue comes from this file:

for (const latest of getLatestValueByDB(latestInLocales)) {

The function is declared here:

const getLatestValueByDB = (latest) => {

@omikulcik omikulcik added the Issue: help wanted Looking for someone to tackle this issue label Aug 14, 2023
@omikulcik
Copy link
Collaborator

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.

@craigbloodworth
Copy link

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

@omikulcik
Copy link
Collaborator

@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.

@ZirixCZ
Copy link
Author

ZirixCZ commented Aug 21, 2023

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 ❤️

@ZirixCZ ZirixCZ closed this as completed Aug 21, 2023
@jonathanclouda
Copy link

it fixes also on version:

  • strapi: 4.20.0
  • plugin: 1.2.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: help wanted Looking for someone to tackle this issue
Projects
None yet
Development

No branches or pull requests

4 participants