projects.approvals_before_merge can be NULL in the application but not in the DB

The column projects.approvals_before_merge is defined as NOT NULL in the database. The application however has the following validation:

validates :approvals_before_merge, numericality: true, allow_blank: true

This allows nil / null values. When setting such a value and saving a project this will lead to a DB error, possibly producing an HTTP 500 instead of a proper validation error. This is already happening on GitLab.com, from our PostgreSQL logs:

ERROR: null value in column "approvals_before_merge" violates not-null constraint
Assignee Loading
Time tracking Loading