Don't require comment if no audited_changes present #522
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change
If a model requires audit comments, but you only change attributes that are excluded from auditing, then don't require an audit comment.
Example of need
I'm working on a project with Southwark Council. We are creating a public audit log of changes to affordable housing in the local area. I have needed to monkey patch this fix/feature in twice:
dxw/affordable-housing-monitoring@1f0bc0d#diff-70e52879b0769bbfd76a2cc96ac3e32aR38 - I don't want to create an audit log entry when changing the aasm state field. By adding the
state
field as an excluded column, this fixes that, but then creates a validation error if I turn oncomment_required
dxw/affordable-housing-monitoring@b5c6475#diff-02864dac712ea1f466e4165075e103cdR23 - A different user of the system edits two attributes on this model to the other attributes on the model, and I don't want to create audit logs for these either. Same problem as above
Considerations
I am pretty certain that this is a bug when it comes to updating a model. However, my suggested fix also makes it so that an audit comment isn't required if you're creating a model where only excluded attributes are present. I think there is more room for debate around whether this is expected/desired behaviour.