Undefined setting creating errors on import/export
oriooctopus opened this issue · 14 comments
Describe the bug
This video describes the bug: https://drive.google.com/file/d/1ALFiP7iSfEzvBaSbsPBdk0TsLnZ2EkXz/view
And here is the error logged to my console:
Error: TypeError: Cannot read property 'code' of undefined
at Object.exportSingleConfig (/Users/macuser/coding/acc-v4/node_modules/strapi-plugin-config-sync/server/services/main.js:252:13)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async /Users/macuser/coding/acc-v4/node_modules/strapi-plugin-config-sync/server/controllers/config.js:22:9
at async Promise.all (index 37)
at async Object.exportAll (/Users/macuser/coding/acc-v4/node_modules/strapi-plugin-config-sync/server/controllers/config.js:21:7)
at async returnBodyMiddleware (/Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
at async policiesMiddleware (/Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
at async /Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/middlewares/body.js:25:7
at async /Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/middlewares/logger.js:22:5
at async /Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/middlewares/powered-by.js:16:5
at async cors (/Users/macuser/coding/acc-v4/node_modules/@koa/cors/index.js:95:16)
at async /Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/middlewares/errors.js:13:7
at async session (/Users/macuser/coding/acc-v4/node_modules/koa-session/index.js:41:7)
at async /Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/services/metrics/middleware.js:29:5
Potentially useful is a different error when I run "import"
[2022-04-23 12:43:28.971] error: TypeError: Cannot read property 'permissions' of null
Error: TypeError: Cannot read property 'permissions' of null
at Object.importSingleConfig (/Users/macuser/coding/acc-v4/node_modules/strapi-plugin-config-sync/server/services/main.js:227:13)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async /Users/macuser/coding/acc-v4/node_modules/strapi-plugin-config-sync/server/controllers/config.js:57:7
at async Promise.all (index 0)
at async Object.importAll (/Users/macuser/coding/acc-v4/node_modules/strapi-plugin-config-sync/server/controllers/config.js:56:5)
at async returnBodyMiddleware (/Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
at async policiesMiddleware (/Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
at async /Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/middlewares/body.js:25:7
at async /Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/middlewares/logger.js:22:5
at async /Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/middlewares/powered-by.js:16:5
at async cors (/Users/macuser/coding/acc-v4/node_modules/@koa/cors/index.js:95:16)
at async /Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/middlewares/errors.js:13:7
at async session (/Users/macuser/coding/acc-v4/node_modules/koa-session/index.js:41:7)
at async /Users/macuser/coding/acc-v4/node_modules/@strapi/strapi/lib/services/metrics/middleware.js:29:5
``
### System
- Node.js version: v14.18.1
- NPM version: 6.14.15
- Strapi version: ^4.1.7
- Plugin version: Interestingly it no longer shows a version number, it is:
`"strapi-plugin-config-sync": "boazpoolman/strapi-plugin-config-sync"`
- Database: postgres
- Operating system: MacOS
Hey @oriooctopus!
Thanks for the bug report.
Just to be sure:
This issue was there for you on v1.0.0
as wel, right?
Could you also confirm that there are really just 2 records in the database in the table admin_roles
.
It seems to me that for some reason the getAllFromDatabase
function for the admin-role
type actually returns 3 objects of which one the code
attribute is empty.
EDIT:
So if this is the case I have a PR (#52) that will likely fix this.
@oriooctopus could you test this?
Hey! Thanks for the fast response. A few things:
- I took a look at my database and there were actually about 10 admin_roles. 2 were valid, the rest were just null/empty rows. However, after deleting them the error still persisted
- I also installed your plugin using the github issue mentioned, then deleted the .cache and builder folder, but it still made no difference on the error.
- I do see one thing different now after doing the above two things. Instead of the setting causing the error being an empty row, I see some information in it now:
Thanks for the donation man <3
One thing that caught my attention was that you only have 2 roles in the database (super-admin and editor).
Then you remove all the invalid admin_roles
records from the database, so only 2 are left.
But in the screenshot you are now presented with a strapi-author item.
So where does that admin-role
come from if you only have the 2 other roles in the database. Is that automatically recreated or something? I couldn't reproduce. I don't have the EE so might be a difference there.
Yeah of course! I think the work you're doing is great :)
And in the config/sync/
dir; is there a file for the strapi-author
admin role? Or also no.
EE stands for Enterprise Edition. Aka the paid version of Strapi which is needed to add, update and delete admin roles through Strapi admin.
If you could try debugging that would be great. A starting point could be to check out this service: https://github.com/boazpoolman/strapi-plugin-config-sync/blob/master/server/services/main.js#L263
It is used to show your the diff in the admin panel. In there you should be able to figure out where that strapi-author
record is coming from.
I was able to reproduce the issue from the screenshot by placing an empty admin-role.strapi-author.json
file in the /config/sync
directory.
I've updated the PR to also check for empty config files and throw a warning on that, instead of an error.
@oriooctopus could you test the PR again?
yarn add boazpoolman/strapi-plugin-config-sync#pull/52/head
npm install boazpoolman/strapi-plugin-config-sync#pull/52/head
So strangly, everything now works!? This error has existed for a few weeks I believe, at least 2. I didn't do anything special this time except this time when I deleted all the config sync files and reexported my current settings, I had the debugger on and it only exported about half before a DB timeout occurred. Perhaps this issue was due to a race condition?
I also want to add that I did have a strapi-author
file
So after installing the PR everything started working again? Or even without the PR?
A DB timeout seems less then ideal. And quitte weird as wel as we're querying < 100 records.
What do you mean by the debugger? Which debugger.
Well it timed out because I had the debugger on and took my time stepping through everything. Sorry, by debugger I mean the vscode node debugger.
The thing is, in the previous day I had tried it with that installed PR with no improvement. However, perhaps I hadn't tried the specific combination of having that PR installed, deleting all my config sync files, and re-exporting. Maybe that's what happened.
Allright, got it. I'm gonna go ahead and assume that the PR fixes the issue then.
Though the real question remains; how did we get here?
Why were those empty records in your DB?
I'm gonna close this issue, but if you ever find yourself in a similar situation, or have any new insights on how those empty records came into the DB feel free to re-open the issue or create a new one.
Thanks for testing and helping me improve this plugin 🚀
Thank YOU! Really appreciate this plugin :)
The PR was released with v1.0.1
btw.