Skip to content

add methodQuery parameter for patch and update - #181

Closed
sechel wants to merge 3 commits into
feathersjs:masterfrom
sopherio:master
Closed

add methodQuery parameter for patch and update#181
sechel wants to merge 3 commits into
feathersjs:masterfrom
sopherio:master

Conversation

@sechel

@sechel sechel commented May 6, 2020

Copy link
Copy Markdown

I have come across this twice in the last two weeks and decided to draft a solution. When I update a field that is included in the query of an update or patch call, then the subsequent get will yield a not found error. This is due to the fact that the query is included in both the update/patch call and the subsequent get.

In this PR i propose to add a separate parameter field methodQuery that is only used in the primary call to updateMany or replaceOne and not used in the subsequent get call.

See also
feathersjs-ecosystem/feathers-hooks-common#584

@DaddyWarbucks

DaddyWarbucks commented May 7, 2020

Copy link
Copy Markdown
Member

There was a recent addition to feathers-sequelize that handled this problem by creating a better findParams. I will take a look at this tomorrow and see if the same solution works.

@DaddyWarbucks

Copy link
Copy Markdown
Member

The problem is similar to that tackled in feathers-sequelize. The updateMany method does not return the documents that were updated. The original query cannot be used in the subsequent findOrGet because the query parameters have changed. In order to fix this, I think we need to do something similar where we get the idList of the documents that are about to change and then apply that to the query that re-fetches the documents. See: https://github.com/feathersjs-ecosystem/feathers-sequelize/blob/1bcfe9f394b619fdad66b956b6df9f6bcd963a8a/lib/index.js#L225

@sechel

sechel commented May 9, 2020

Copy link
Copy Markdown
Author

The problem is similar to that tackled in feathers-sequelize. The updateMany method does not return the documents that were updated. The original query cannot be used in the subsequent findOrGet because the query parameters have changed. In order to fix this, I think we need to do something similar where we get the idList of the documents that are about to change and then apply that to the query that re-fetches the documents. See: https://github.com/feathersjs-ecosystem/feathers-sequelize/blob/1bcfe9f394b619fdad66b956b6df9f6bcd963a8a/lib/index.js#L225

Ok, I'm going to change this PR along these lines then.

@ericirish

Copy link
Copy Markdown
Contributor

@sechel any updates on this? Experiencing this with SoftDelete as well.

@DaddyWarbucks

Copy link
Copy Markdown
Member

@ecirish I believe this was fixed with feathersjs-ecosystem/feathers-mongoose#330
The patch method should return the patched records correctly.

Which softDelete are you using?

@ericirish

Copy link
Copy Markdown
Contributor

@DaddyWarbucks I'm using the latest SoftDelete from feathers-hooks-common, but I'm not using Mongoose. Just feathers-mongodb.

@DaddyWarbucks

Copy link
Copy Markdown
Member

Oh! Whoops, my bad! I got the adapter repos crossed. From the looks of https://github.com/feathersjs-ecosystem/feathers-mongodb/blob/6bf168269f7cbb9f329cc8a530d5ee7677b645f7/lib/index.js#L215 this is still a bug here in this adapter. I will try to make some time tomorrow to fix this. I fixed similar issues in Mongoose and Sequelize, so this should be pretty straightforward.

@ericirish

Copy link
Copy Markdown
Contributor

@DaddyWarbucks Wow. Thanks for the prompt reply and the even more impressive prompt action!

@sechel

sechel commented Sep 23, 2020

Copy link
Copy Markdown
Author

@sechel any updates on this? Experiencing this with SoftDelete as well.

I also had issues with softDelete that led me to this PR. Great that @DaddyWarbucks is looking into this as I have not the time to do so right now.

@daffl

daffl commented Sep 27, 2020

Copy link
Copy Markdown
Member

Thank you for the pull request! This has now been fixed via #188

@daffl daffl closed this Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants