Set iids on before_save callbacks
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
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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