parse-community / parse-community/parse-server

LiveQuery error: protectedFields.forEach is not a function

Open
#8,798 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

New Issue Checklist
Issue Description

error: Failed running afterLiveQueryEvent on class Message for event create with session r:... with: Error: {"message":"protectedFields.forEach is not a function","code":141}

Steps to reproduce

Run a LiveQuery on class X and then creating+saving a object of class X. E.g. in my case using Swift :

let myClient = ParseLiveQuery.Client()
let lq = myClient.subscribe(queryMessage!)
//... then later ... (much after subscription completes)
let m = Message("hello")
m.saveInBackground { _, error in if error != nil {print(error)} else {print("ok")} }
Actual Outcome

I'm not getting any data in the client from this LiveQuery, and the server says protectedFields.forEach fails. Adding a console.log("protectedFields=",protectedFields) in node_modules/parse-server/lib/Controllers/DatabaseController.js:177 shows protectedFields= { '*': [] } instead of an array, only in this case, whereas it's an array like [] or ["email"] in all other cases (that is, for non-LiveQuery things).

Then I went in Dashboard's Security -> Protected Fields and changed things a bit to see whether the logged value really follows the contents of this form, and so I saw protectedFields= { '*': [ 'stuff', 'moreStuff', 'content' ], authenticated: [ 'otherStuff' ]}. So, when exactly can protectedFields be an array ?

Expected Outcome

No error, and actual LiveQuery results.

Environment

Server

  • Parse Server version: 6.3.1 and also 5.5.6
  • Operating system: Linux
  • Local or remote host: Heroku

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 3.6.12
  • Local or remote host: Heroku ObjectRocket

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): iOS (ParseObjC in Swift)
  • SDK version: 2.7.0
Logs

succeeding :
protectedFields= []
protectedFields= [ 'email' ]

failing :
protectedFields= { '*': [] }
protectedFields= { '*': [ 'stuff', 'moreStuff', 'content' ], authenticated: [ 'otherStuff' ] }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at lib/Controllers/DatabaseController.js:177 and trace how Dashboard Protected Fields values reach afterLiveQueryEvent for LiveQuery creates. Compare the array and object-shaped protectedFields cases using the supplied Message/X reproduction; done when the forEach error is gone and LiveQuery results arrive.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, nodejs
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.