parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Schema API can create a duplicate User class

Open cipiripper opened this issue 10 years ago • 22 comments

Issue Description

You are able to duplicate User class by using Parse REST Schema API.

Steps to reproduce

Run this:

curl -X POST  \
-H "X-Parse-Application-Id: YOUR_APPLICATION_ID"  \
-H "X-Parse-Master-Key: YOUR_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{}' \
http://127.0.0.1:1337/1/schemas/User

Expected Results

Get error: {"code":103,"error":"Class User already exists."}

Actual Outcome

New User class is created, and if you check parse-dashboard, there are two User classes that exist and work in parallel.

But if you try to run the curl again now, you will get the expected result.

cipiripper avatar Jul 20 '16 14:07 cipiripper

The user class actually _User, so that's intended that you can create a User class

flovilmart avatar Jul 20 '16 14:07 flovilmart

I see. Actually this is a parse-dashboard issue.

cipiripper avatar Jul 20 '16 14:07 cipiripper

The dashboard is rendering the _User class as User this is maybe why you thought that was a problem ;)

flovilmart avatar Jul 20 '16 14:07 flovilmart

Actually yes. And the problem is that it shows _User data when you click on User class. Parse-server works good, so this is not an issue.

This returns the correct count of users in _User:

curl -X GET \
  -H "X-Parse-Application-Id: YOUR_APP_ID" \
  -H "X-Parse-Master-Key: YOUR_MASTER_KEY" \
  -G \
  --data-urlencode 'count=1' \
  --data-urlencode 'limit=0' \
  http://127.0.0.1:1337/1/classes/_User

This returns 0, instead of the same count, as it is displayed in parse-dashboard, so User class is created, and it is empty:

curl -X GET \
  -H "X-Parse-Application-Id: YOUR_APP_ID" \
  -H "X-Parse-Master-Key: YOUR_MASTER_KEY" \
  -G \
  --data-urlencode 'count=1' \
  --data-urlencode 'limit=0' \
  http://127.0.0.1:1337/1/classes/User

cipiripper avatar Jul 20 '16 14:07 cipiripper

So that's a dashboard error :)

flovilmart avatar Jul 20 '16 14:07 flovilmart

Is there anyway to remove the second User class from view in the Parse dashboard?

dwby avatar Nov 17 '16 17:11 dwby

Did you try opening weird looking User class in dashboard, and: Edit > Delete this class?

cipiripper avatar Nov 17 '16 17:11 cipiripper

I haven't because my concern is, it will delete the _User class as well!

dwby avatar Nov 17 '16 19:11 dwby

Well it shouldn't, because you created class named User, and you are concerned about deleting _User... You can create a backup of your DB, try to delete it, if something goes wrong, restore backup.

cipiripper avatar Nov 18 '16 14:11 cipiripper

@dwby Were you able to remove the second User class from view in the Parse dashboard? If yes, how did you do it?

yoterpa avatar Mar 15 '17 13:03 yoterpa

@cipiripper But it won't let me delete the class before deleting all the rows first. And deleting the rows in the duplicate User class deletes the corresponding rows in default User class as well.

yoterpa avatar Mar 15 '17 13:03 yoterpa

@yoterpa Did you try to open mongo shell and remove the class directly from DB? User class is empty in DB, so that restriction you are seeing in dashboard is because of dashboard that mistakenly shows _User data in User class, so it expects all data to be removed... and mongo shell doesn't have this restriction and mixing of class names.

To be honest, I am not sure how I did this... I really don't remember... :) So I am starting to think that I never did remove it, but I removed the whole DB and migrated it again from Parse...

cipiripper avatar Mar 15 '17 14:03 cipiripper

@cipiripper Yes I removed the class directly from DB, but it is still being shown in the Dashboard. Is there anything else I can try other than backup-restore?

yoterpa avatar Mar 15 '17 18:03 yoterpa

@yoterpa Weird... Maybe try to clear cache in browser, restart/reinstall parse-dashboard process? I mean, if you have removed it from DB, then there shouldn't exist anymore... BUT I am not sure what happens if you actually save a User object instead of _User... :)

cipiripper avatar Mar 15 '17 18:03 cipiripper

@cipiripper Clearing browser cache didn't help. As per your suggestion, I tried adding a User object from dashboard which successfully creates a new object, but as soon as I refresh the tab it disappears. I checked the db in mongo-shell and found that User class got created again. :(

yoterpa avatar Mar 15 '17 19:03 yoterpa

Yes, well that's how parse works... If there is no class, it creates it... Just don't create new Users, but Parse.User or _User... and remove all User objects and class from db. I guess that this must work...

cipiripper avatar Mar 15 '17 19:03 cipiripper

I have already deleted the User class from mongo-shell, cleared browser cache, restarted parse-server and dashboard, but the issue still persists.

yoterpa avatar Mar 15 '17 19:03 yoterpa

@yoterpa How did you delete it? Using drop() or remove()? Try drop()? Also be sure that there is no after delete trigger that re-creates the user, and remove all User relations if any...

I'm out of ideas. Good luck. :)

cipiripper avatar Mar 15 '17 19:03 cipiripper

I used drop(). There is no after delete trigger. There is a relation but to _User class, NOT User class.

Thanks a lot for your help. :) I will try something else.

yoterpa avatar Mar 15 '17 20:03 yoterpa

You will also probably need to remove the User document from the _SCHEMA collection and restart your server and dashboard

steven-supersolid avatar Mar 16 '17 10:03 steven-supersolid