Budibase / budibase

Low code platform for building business apps and workflows in minutes. Supports PostgreSQL, MySQL, MariaDB, MSSQL, MongoDB, Rest API, Docker, K8s, and more 🚀
https://budibase.com
Other
22.51k stars 1.55k forks source link

[BUDI-7099] MySQL - Converting circular structure to JSON #10834

Closed diogenesbrussels closed 1 year ago

diogenesbrussels commented 1 year ago

Hosting

Describe the bug After the update, data requests via the API/table/search on certain tables generate the following error: Converting circular structure to JSON

To Reproduce Steps to reproduce the behavior:

  1. Have a MySQL table with relationships (here a person have multiple actions rows linked)
  2. Open the data tab of this table or use it in a data provider
  3. The table/ data provider is empty (error 500)
  4. Converting circular structure to JSON --> starting at object with constructor 'Object' | property 'XXXXXXX' -> object with constructor 'Array' | index 0 -> object with constructor 'Object' | property 'primaryDisplay' -> object with constructor 'Array' --- index 0 closes the circle

Expected behavior The data must be sent as before.

Additional context I had to change all the data provider for this table to sql queries to resolve this. Has the way relationships are resolved changed? Is there a list of breaking changes between releases? The last 3 updates I made created errors in an existing application without any problems. I'd like to keep an up-to-date version as much as(for example, some components display a missing order by column error, even though no sort order has been defined, but if I select one it works again) possible to take advantage of your great work, but this type of problem makes me wonder about this for the future. (for example, some components display a missing order by column error, even though no sort order has been defined previously, but if I select one it works again :/) Thank you!

BUDI-7099

mike12345567 commented 1 year ago

Hi @diogenesbrussels - I've given this a test, using a MySQL database, with a Person and Tasks table - configuring the tasks with a PersonID foreign key then setting up this relationship with Budibase.

The data is loaded fine as shown below: image

I'm wondering if you could provide a bit more information here, such as the schema of two tables or some screenshots of the error as you see it? If there is a network request that fails it would also be good to see a screenshot of the failing request to help with debugging.

Also, if there is a failing network request, it would be great if you could provide the logs from the app-service container right after the error occurs, as this should give us a bit more information about what is happening.

diogenesbrussels commented 1 year ago

Hey @mike12345567

Here is the log when opening one of the table in the Data section:

2023-06-12 13:39:56 {"level":"ERROR","timestamp":"2023-06-12T11:39:56.090Z","err":{"type":"TypeError","message":"Converting circular structure to JSON\n    --> starting at object with constructor 'Object'\n    |     property 'people_tasks' -> object with constructor 'Array'\n    |     index 0 -> object with constructor 'Object'\n    |     property 'primaryDisplay' -> object with constructor 'Array'\n    --- index 0 closes the circle","stack":"TypeError: Converting circular structure to JSON\n    --> starting at object with constructor 'Object'\n    |     property 'people_tasks' -> object with constructor 'Array'\n    |     index 0 -> object with constructor 'Object'\n    |     property 'primaryDisplay' -> object with constructor 'Array'\n    --- index 0 closes the circle\n    at JSON.stringify (<anonymous>)\n    at Object.get length [as length] (/app/node_modules/koa/lib/response.js:215:35)\n    at /app/node_modules/koa-compress/lib/index.js:58:35\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)"},"tenantId":"default","correlationId":"75cb56d2-f612-487d-b8dc-a58672485850","msg":""}
2023-06-12 13:39:56 {"level":"INFO","timestamp":"2023-06-12T11:39:56.092Z","req":{"method":"POST","url":"/api/datasource_plus_xx__people/search","correlationId":"75cb56d2-f612-487d-b8dc-a58672485850"},"res":{"status":500},"err":{"type":"Error","message":"failed with status code 500","stack":"Error: failed with status code 500\n    at ServerResponse.onResFinished (/app/node_modules/koa-pino-logger/node_modules/pino-http/logger.js:107:40)\n    at ServerResponse.emit (events.js:412:35)\n    at ServerResponse.emit (domain.js:475:12)\n    at onFinish (_http_outgoing.js:792:10)\n    at callback (internal/streams/writable.js:513:21)\n    at afterWrite (internal/streams/writable.js:466:5)\n    at afterWriteTick (internal/streams/writable.js:453:10)\n    at processTicksAndRejections (internal/process/task_queues.js:81:21)"},"responseTime":723,"msg":"request errored"}

And in the browser console:

[Builder] HTTP 500 on POST:https://xxx/api/datasource_plus_xx__people/search
    Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'people_tasks' -> object with constructor 'Array'
    |     index 0 -> object with constructor 'Object'
    |     property 'primaryDisplay' -> object with constructor 'Array'
    --- index 0 closes the circle [index.4ca5529d.js:1:981](https://xxx/builder/assets/index.4ca5529d.js)
XHRPOST
https://xxx/api/datasource_plus_xx__people/search
[HTTP/3 500 Internal Server Error 130ms]

[Builder] HTTP 500 on POST:https://xxx/api/datasource_plus_xx__people/search
    Unknown column 'people_tasks.task' in 'order clause'

Let me know if you need more details, I can email you the table structure as I don't want to share them publicly.

mike12345567 commented 1 year ago

Hi @diogenesbrussels - if you could email the table schema to support@budibase.com that would be great.

mike12345567 commented 1 year ago

Hi @diogenesbrussels - I believe that this maybe something to do with the primary display columns of your tables. I'm going to push a fix for this which will handle this correctly and display an error message for the relationships as the configuration is invalid - we changed our handling of these type of situations recently - i'm not sure how in your case a relationship field has been used as a primary display field; but that appears to be what has happened.

diogenesbrussels commented 1 year ago

Hey @mike12345567 Thanks! I manually changed the incorrect primaryDisplay of one of the two tables and that solved the problem!