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

Sorting by non-existing field returns http error 500 #8072

Closed
4 tasks done
MrMartinR opened this issue Jun 26, 2022 · 16 comments · Fixed by #8157
Closed
4 tasks done

Sorting by non-existing field returns http error 500 #8072

MrMartinR opened this issue Jun 26, 2022 · 16 comments · Fixed by #8157
Labels
state:released Released as stable version state:released-5.x.x Released as LTS version state:released-alpha Released as alpha version state:released-beta Released as beta version type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@MrMartinR
Copy link

New Issue Checklist

Issue Description

If I delete a field that was previously sorted/ordered in Parse Dashboard, when I try to load the records from that class, returns a 500 error.

Steps to reproduce

I created a column (named ‘s’) in the Contact class to test the schema, then I deleted it via Dashboard and via JS SDK but when I click on the dashboard Contact Class, no records are showing, and parse server log complains with error:

error: column "s" does not exist {"code":1,"stack":"Error: error: column \"s\" does not exist\n    at /Users/Martin/Dev/Parse-Server/node_modules/parse-server/lib/Controllers/DatabaseController.js:1164:21\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)"}

If I create the field again (via dashboard or via JS) the error goes away and the records appear

I found the cause in the POST request when I select the Contact Class that returns a 500 error

XHRPOST http://localhost:1337/parse/classes/Contact
[HTTP/1.1 500 Internal Server Error 6ms]
_ApplicationId	"appId"
_ClientVersion	"js3.4.1"
_InstallationId	"8ad5475f-30e5-4a1"
_MasterKey	"masterKey"
_method	"GET"
limit	200
order	"s"  //<-- here is where I realize the problem
where	{}

Actual Outcome

Error 500

Expected Outcome

Not get the error and load the records

Environment

Local environment

Server

  • Parse Server version: 5.3.2
  • Operating system: macOS Monterrey
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local

Database

  • System (MongoDB or Postgres): Postgres
  • Database version: 14.3
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Local (I did not tried in remote)

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): JavaScript
  • SDK version: 3.4.2

Logs

@parse-github-assistant
Copy link

parse-github-assistant bot commented Jun 26, 2022

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza
Copy link
Member

mtrezza commented Jun 26, 2022

So the dashboard is trying to sort by a field that doesn't exist, right?

It's expected that Parse Server returns an error, but it should be a 4xx, not 5xx.

Parse Dashboard also cannot know whether a field still exists before making the query, unless it fetched the schema before each query. So it can either fetch the schema which may be an overhead we don't want, or it should display a proper error that one of the fields doesn't exist. For that, Parse Server needs to returns a proper error code, presumably http 400 and the corresponding Parse.Error code.

@MrMartinR
Copy link
Author

So the dashboard is trying to sort by a field that doesn't exist, right?

Yes, to be honest, not sure if this issue is even a parse-server thing...

Quickly thinking a solution should be adding some "check" in parse-dashboard, something like removing the "order" flag in the class before deleting the field in case the class is being sorted by the target field.
(Or unsort the field by applying the parse-dashboard feature parse-community/parse-dashboard#2178)
Doing this check on deletion, we should not see the 500 error from parse-server anymore

I am assuming that the order is stored in the class somewhere and that the order/sort can only be applied on parse-dasboard, not thru the SDKs.

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Jun 26, 2022
@mtrezza
Copy link
Member

mtrezza commented Jun 26, 2022

removing the "order" flag in the class before deleting the field in case the class is being sorted by the target field.

sounds good, but this is a Parse Dashboard issue that needs to be opened separately

(Or unsort the field by applying the parse-dashboard feature parse-community/parse-dashboard#2178)

This is a feature request to manually remove the sort; unrelated to the logic suggested above.

Doing this check on deletion, we should not see the 500 error from parse-server anymore

As discussed, Parse Server should not throw 5xx, but 4xx when sorting by a non-existing field. This is the only issue that needs to be addressed on the Parse Server side, and this issue here should only focus on that. Anything else that concerns Parse Dashboard or SDK side are separate issues that need to be opened in the respective repos.

I am assuming that the order is stored in the class somewhere and that the order/sort can only be applied on parse-dasboard, not thru the SDKs.

There is no server side order; order is a parameter of a query. If a developer deletes a field and then sends a query using an SDK, it is the developer's responsibility to account for the deletion of that field by adapting the query; or properly handle the 4xx server response in case the field doesn't exist anymore.

@MrMartinR
Copy link
Author

There is no server side order; order is a parameter of a query. If a developer deletes a field and then sends a query using an SDK, it is the developer's responsibility to account for the deletion of that field by adapting the query; or properly handle the 4xx server response in case the field doesn't exist anymore.

mm.. still confused, the 500 error comes from the parse-dashboard page (not from the server?)
image

I think parse-dashboard sends some log to parse-server that pops in the parse-server terminal, but from the SDK I can fetch the data with no problems or errors in the browser inspector.
image

Parse-server logs file shows:

{"code":1,"level":"error","message":{"code":"42703","file":"parse_relation.c","length":101,"line":"3599","name":"error","position":"35","routine":"errorMissingColumn","severity":"ERROR"},"stack":"Error: error: column \"s\" does not exist\n    at /Users/Martin/Dev/Parse-Server/node_modules/parse-server/lib/Controllers/DatabaseController.js:1164:21\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)","timestamp":"2022-06-26T12:13:30.831Z"}
{"code":1,"level":"error","message":{"code":"42703","file":"parse_relation.c","length":101,"line":"3599","name":"error","position":"35","routine":"errorMissingColumn","severity":"ERROR"},"stack":"Error: error: column \"s\" does not exist\n    at /Users/Martin/Dev/Parse-Server/node_modules/parse-server/lib/Controllers/DatabaseController.js:1164:21\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)","timestamp":"2022-06-26T19:27:32.959Z"}

Note that if I create the field again, automatically shows the sort arrow, so the order/sort of the class "viewer" has to be stored somewhere 🤔🤷‍♂️
image

not sure if related, but I cannot access the Logs in my local dev parse-server installation via parse-dashboard.
image
If I press the "Logs" I got a blank screen and lots of errors in the inspector.. (I did not dig into this problem yet...)

@mtrezza
Copy link
Member

mtrezza commented Jun 26, 2022

This is the Parse Server issue, so let's focus on the Parse Server side here and forget about the dashboard for now.

The 500 http error comes from the server. Parse Server should never return a 500 error; it means that something wasn't handled properly inside Parse Server. The usual approach would be to create a PR with a failing test. Just write a minimal code example and try to reproduce what you observe, so that the test fails with a 500 code. As I understand, the test would be to create a query and order by a non-existing field. The test should expect a 4xx error with the correct Parse.Error. Looking at the error codes it should probably be 105, InvalidFieldName; but you'd have to check which error is returned when you specify an in valid field name for other constraints, like a equalTo.

Anything else that is Parse Dashboard related should be discussed in a separate issue in that repo.

@mtrezza mtrezza changed the title Deleting a Field that was sorted in Parse Dashboard Returns error 500 Sorting by non-existing field returns http error 500 Jun 26, 2022
@dblythy
Copy link
Member

dblythy commented Sep 8, 2022

@MrMartinR I have tried to replicate this but have been able. I am on the latest dashboard and parse server.

I've tried to manually add the invalid order key to the fetch payload, here is the request:

fetch('PARSE_URL/classes/_User', {
  body: JSON.stringify({
    order: 's',
    where: {},
    _ApplicationId: APP_ID,
    _ClientVersion: 'js3.4.2',
    _MasterKey: MASTER_KEY,
    _method: 'GET',
  }),
  method: 'POST',
})
  .then(res => res.json())
  .then(obj => console.log(obj));

@MrMartinR
Copy link
Author

@dblythy are you getting the error500?

@dblythy
Copy link
Member

dblythy commented Sep 8, 2022

No I wasn't, I'm getting results

@MrMartinR
Copy link
Author

I'm using Dashboard 4.2.0-ALPHA.4 and Server 3.4.3, if the column s doesn't exist I assume you getting the results with no errors and unsortered?
Just to be clear: Sort a column from the Dashboard (the column header shows the little arrow), delete the column, change to another class/table, change back again to the class/table where the sort field was deleted, I got no records showing on Dashboard and the Error500 on parse server terminal.

@dblythy
Copy link
Member

dblythy commented Sep 8, 2022

Ahh, in my testing I was using mongo. I’ll try again with Postgres tomorrow

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.3.0-alpha.26

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Sep 17, 2022
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.4.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Oct 29, 2022
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.4.0-alpha.1

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.4.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Nov 19, 2022
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.4.0

@parseplatformorg parseplatformorg added the state:released-5.x.x Released as LTS version label Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-5.x.x Released as LTS version state:released-alpha Released as alpha version state:released-beta Released as beta version type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants