Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix #53: Add validation for $set, $unset Update operations not to allow changing _id #54

Merged
merged 6 commits into from
Jan 27, 2023

Conversation

tatu-at-datastax
Copy link
Contributor

@tatu-at-datastax tatu-at-datastax commented Jan 27, 2023

Changed the way Update operations are handled: instead only having UpdateOperator and DocumentUpdater implementing logic there is now base type UpdateOperation and construction happens in 2 separate phases:

  1. Simpler deserialization from JSON into UpdateClause; binds UpdateOperator marker but not JSON Object that configures operation
  2. UpdateClause.buildOperations() will construct UpdateOperations and handle cross-operation validation -- this will allow passing more configuration if necessary, in future (for Upsert handling etc)

With the logic separated more validation is done:

  1. We will check if Update operator is valid (starts with "$"); and if so if we actually support it (added $inc as an example of known but not yet supported)
  2. "$set" and "$unset" must not be used on _id (now checked)
  3. "$set" and "$unset" must not be used for same path (cannot both set and unset 'x' etc)

This change is the base to start adding handling for nested properties (sub-documents).
Could also consider implementing "$inc" operator since it seems relatively straight-forward.

@tatu-at-datastax tatu-at-datastax changed the title Fix #53: Add validation for $set, $unset Update operations not to allow changing _id WIP: Fix #53: Add validation for $set, $unset Update operations not to allow changing _id Jan 27, 2023
@maheshrajamani
Copy link
Contributor

Looks good to me.

@tatu-at-datastax tatu-at-datastax merged commit 16bc877 into main Jan 27, 2023
@tatu-at-datastax tatu-at-datastax deleted the tatu/53-prevent-id-change-via-set-unset branch January 27, 2023 16:52
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.

2 participants