NoMethodError: undefined method `branch_allows_maintainer_push?' for nil:NilClass

https://sentry.gitlap.com/gitlab/gitlabcom/issues/153537/

NoMethodError: undefined method `branch_allows_maintainer_push?' for nil:NilClass
  lib/gitlab/user_access.rb:66:in `can_push_to_branch?'
    return false unless user.can?(:push_code, project) || project.branch_allows_maintainer_push?(user, ref)
  lib/gitlab/cache/request_cache.rb:76:in `block (3 levels) in request_cache'
    store.fetch(key) { store[key] = super(*args) }
  lib/gitlab/cache/request_cache.rb:76:in `fetch'
    store.fetch(key) { store[key] = super(*args) }
  lib/gitlab/cache/request_cache.rb:76:in `block (2 levels) in request_cache'
    store.fetch(key) { store[key] = super(*args) }
  app/services/commits/create_service.rb:48:in `validate_permissions!'
    allowed = ::Gitlab::UserAccess.new(current_user, project: project).can_push_to_branch?(@branch_name)
...
(142 additional frame(s) were not displayed)

NoMethodError: undefined method `branch_allows_maintainer_push?' for nil:NilClass