ent icon indicating copy to clipboard operation
ent copied to clipboard

Fix IDs() to respect mutation predicates for UpdateOne and DeleteOne

Open mwoelk opened this issue 1 year ago • 5 comments

Fixes issue #3883

Summary

Updated the generated IDs() function on mutations.

Checks during OpUpdateOne and OpDeleteOne if there are any predicates set on the mutation and if yes, adds another predicate with the id of the mutation and runs it against the database to see if the ID is still included after all predicates have been applied.

In case there are no predicates defined, the old behaviour is kept and directly returns the id (to save a query).

mwoelk avatar Jan 03 '24 16:01 mwoelk

@a8m looking forward to your review 👀

mwoelk avatar Jan 03 '24 21:01 mwoelk

@a8m any update on this?

mwoelk avatar Feb 05 '24 11:02 mwoelk

@a8m any update on this?

Mutation should not be tested inside hooks. Instead, create a builder and then call Mutation() - The assertions should apply on this object. If this requires too much time, just clean the tests and one of the team will take it.

You can add a simple case to this function: https://github.com/ent/ent/blob/master/entc/integration/integration_test.go#L2122

a8m avatar Feb 06 '24 12:02 a8m

Saw the failed CI report. Forgot to run generate for the examples directory as well. Should be fixed now :)

mwoelk avatar Feb 07 '24 16:02 mwoelk

Hey @a8m, any chance we can get this merged. Just synced with master again and ran all generate + mod tidy as well as tests. Hopefully should pass CI now :)

mwoelk avatar Apr 11 '24 15:04 mwoelk