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

MongoDB request fails in v3.3.1 - worked fine before #15449

Closed
esellier opened this issue Jan 28, 2025 · 10 comments
Closed

MongoDB request fails in v3.3.1 - worked fine before #15449

esellier opened this issue Jan 28, 2025 · 10 comments
Assignees
Labels
bug Something isn't working env - production Bug found in production firestorm Data/Infra/Revenue Team mongodb MongoDB

Comments

@esellier
Copy link

esellier commented Jan 28, 2025

Checklist

  • [X ] I have searched budibase discussions and github issues to check if my issue already exists

Hosting

  • Self
    • Method: docker
    • Budibase Version: 3.3.1

Describe the bug
A mongo DB request fails with a response :
{"message":"Unexpected token '{' [:1:6]","status":400}

The query works fine if I remove the Transformer. Anything else than the default "return Data;" transformer will fail.

To Reproduce
Steps to reproduce the behavior:
Create query, add a custom transformer => Fails
Remove transformer => OK

@esellier esellier added the bug Something isn't working label Jan 28, 2025
Copy link

linear bot commented Jan 28, 2025

@ConorWebb96
Copy link
Contributor

Hey @esellier,

I've tried to recreate this.

I'm able to do this return data.name (just getting a specific field from an object). Is this also broken for you? Is there a specific piece of JS that you are using that is broken?

Are you using Docker Compose or Docker Single Image? If you let me know which one you are using, I'll try to recreate it on those as well.

@esellier
Copy link
Author

AFAIK, we use docker-compose.
I tried return data?.name with an empty response but it also fails.

Image

@esellier
Copy link
Author

I tried on my own Macbook, with a new clone of the git repo and running in Docker (npm run dev:docker), it works fine.

@esellier
Copy link
Author

The problem is in query.ts:155, when executing the transformer in VM.
There is an exception :
{ "userScriptError": {}, "code": "USER_SCRIPT_ERROR" }
The script passed to vm.execute is OK.

@mike12345567
Copy link
Collaborator

mike12345567 commented Jan 28, 2025

Hi @esellier - I've been trying to replicate this - but the only way I've been able to get the error is with invalid JS. In your example data?.name is not valid JS, the optional chaining operator is not available in Node.

I've tried quite a few different examples in 3.3.3 and have not been able to recreate with any valid transformer - below is your example from Discord.

Image

@esellier
Copy link
Author

Extracted from /tmp/.budibase/systemlogs/budibase.log
{"level":"WARN","timestamp":"2025-01-28T20:20:27.033Z","service":"@budibase/server","err":{"type":"SyntaxError","message":"Unexpected token '{' [:1:6]","stack":"SyntaxError: Unexpected token '{' [:1:6]\n at gm.withParsingBson (/app/dist/query.js:566:365)\n at e.execute (/app/dist/query.js:849:39113)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async r (/app/dist/query.js:849:41544)\n at ()\n at withParsingBson (/app/dist/query.js:566:365)\n at execute (/app/dist/query.js:849:39113)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)","$error":"$error","expose":true,"statusCode":400,"status":400},"pid":29,"tenantId":"default","correlationId":"50f163f8-ab3f-4ee7-be3a-f6b929f2b4f4","msg":""}

@esellier
Copy link
Author

esellier commented Jan 28, 2025

Issue found... It's strange.
In the minified version of query.js at line 566, there is a declaration of a class without name.
let n=class{constructor(...o){this.constructorArgs=o}
It should be
let n=class TextDecoderMock{constructor(...o){this.constructorArgs=o}
This is why we have this error about a misplaced '{' character.

I can't say however why the classname disappears in the minified version.
This bug is only for MONGODB and in any query using a transformer.
All works fine when the class name is set in query.js.

On my Macbook, the query.js script is not minified and the class name is OK... and that's why it was running fine.

@esellier
Copy link
Author

esellier commented Jan 28, 2025

Hi @esellier - I've been trying to replicate this - but the only way I've been able to get the error is with invalid JS. In your example data?.name is not valid JS, the optional chaining operator is not available in Node.

Optional chaining is available in NodeJS, since version 14.

Welcome to Node.js v20.18.2.
Type ".help" for more information.
> a=undefined
undefined
> a?.name === undefined
true

@adrinr adrinr assigned adrinr and unassigned ConorWebb96 Jan 29, 2025
@ConorWebb96 ConorWebb96 added env - production Bug found in production firestorm Data/Infra/Revenue Team labels Jan 29, 2025 — with Linear
@adrinr
Copy link
Collaborator

adrinr commented Jan 30, 2025

This should be fixed on version 3.3.5. Thank you for the details on your research, @esellier!

@adrinr adrinr closed this as completed Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working env - production Bug found in production firestorm Data/Infra/Revenue Team mongodb MongoDB
Projects
None yet
Development

No branches or pull requests

4 participants