parse-community / parse-community/parse-server
Parse.Cloud.httprequest fails to delete file with S3 adapter
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest version of Parse Server.
Issue Description
Deleting a file in Cloud Code via REST deletes the file from S3 even though it results in a 400 Bad request response:
await Parse.Cloud.httpRequest({
method: "DELETE",
url: 'https://example.com/parse/files/file.txt',
headers: {
'X-Parse-Application-Id': appId,
'X-Parse-Master-Key': masterKey,
'Content-Type': 'application/json'
}
});
The http response is 400 Bad request, but the file is deleted from S3. This has been working before, but it doesn't anymore since some time (weeks, months?), not sure which change caused it to fail, it may even be something in the AWS S3 adapter.
Interestingly, it works without issue to delete the same file
- with the same parameters via REST API outside of Cloud Code / Node.js
- via
Parse.File.destroy()
Because it works with a direct REST request, the issue may well be in Parse.Cloud.httprequest, therefore I post this as a Parse Server issue.
I have been debugging this down into the AWS S3 SDK, but I wasn't able to fully pin the issue. Looking at the Parse Server S3 adapter's deleteFile:
deleteFile(filename) {
return this.createBucket().then(() => new Promise((resolve, reject) => {
const params = {
Key: this._bucketPrefix + filename,
};
this._s3Client.deleteObject(params, (err, data) => {
if (err !== null) {
return reject(err);
}
return resolve(data);
});
}));
}
It seemed as if each AWS S3 client method returns twice, once with a 400 response and once with the actual successful 200 callback. In other words, each of createBucket and deleteObject returns twice, but on the first return of createBucket, the deleteFile method returns, passing the 400 response to the original Parse.Cloud.httpRequest.
The Parse Server S3 adapter does not have Parse Server integration tests, and Parse Server does not test with the adapter, so I wasn't sure how to write a failing test case. Would be great if someone could try to reproduce this.
@dplewis You added the Parse.File.destroy method to the Parse JS SDK recently, maybe you came across something like this?
Steps to reproduce
- Use Parse Server S3 adapter.
- Save a file.
- Delete file in Cloud Code with
Parse.Cloud.httpRequestas shown above.
Actual Outcome
Parse.Cloud.httpRequest should return correct response.
Expected Outcome
Parse.Cloud.httpRequest returns incorrect response, 400 instead of 200, even though the file is deleted from S3.
Failing Test Case / Pull Request
- 🤩 I submitted a PR with a fix and a test case.
- 🧐 I submitted a PR with a failing test case.
Environment
Server
- Parse Server version:
commit 2b9b336dd9d388ddb1b4099b87ff6a0d679199d7 - Operating system:
- - Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc):
local and remote
Database
- System (MongoDB or Postgres):
irrelevant - Database version:
irrelevant - Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
irrelevant
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc):
Parse JS SDK in Cloud Code - SDK version:
3.1
Logs
(none)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the listed save-and-delete steps with Parse.Cloud.httpRequest, then inspect the Parse Server S3 adapter's index.js deleteFile implementation and the Cloud Code HTTP request path. Confirm why the response is 400 while S3 deletion succeeds, and verify that the request returns the correct 200 response without breaking direct REST deletion or Parse.File.destroy().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript, nodejs
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100