Avoid using before_validation or before_save to change the values

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

  • Close this issue

The following discussion from gitlab-ce!12509 should be addressed:

  • @grzesiek started a discussion: (+7 comments)

The reason why I think changing the values in validation is bad is because:

@grzesiek Do you mean we should remove / in before_validate? It was like that before, but to think about it, I really don't like the idea that calling valid? would change the data:

project.valid? # => then data would be changed

I think this is surprising and changing data isn't really validating.

An alternative way would be overriding the assignment method like this:

def ci_config_file=(value)
  # Strip all leading slashes so that //foo -> foo
  super(value&.sub(%r{\A/+}, ''))
end
Edited Sep 28, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading