Skip to content

Set iids on before_save callbacks

Patrick Bair requested to merge 292225-atomic-internal-id-edge-cases into master

What does this MR do?

Related to #292225 (closed)

Prevent edge cases described in the related issue by moving the generation of iid values to before_create and before_update rather than before_validation.

Since iid generation only happens once the model is valid according to application logic, a failure to save at that point should result in an exception/transaction rollback. To prevent the application from catch/retry such an error, use an after_rollback callback to unset the iid value on the model if it was previously set in the ensure_#{scope}_iid! method.

In cases where the iid value was already persisted on the model, or where the ensure_iid! logic was skipped, don't clear the attribute on the model.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Patrick Bair

Merge request reports