Gitlab 报错:Error 500 with /api/v4/projects: NoMethodError: undefined method `string_access_level‘

新安装的gitlab1.14.1版本在调用查询所project的api时,会报如下错误:

NoMethodError: undefined method `string_access_level' for nil:NilClass
  api/entities.rb:276:in `block in <class:Project>'
    expose(:issues_access_level) { |project, options| project.project_feature.string_access_level(:issues) }
  grape_entity/entity.rb:496:in `instance_exec'
    instance_exec(object, options, &block)
  grape_entity/entity.rb:496:in `exec_with_object'
    instance_exec(object, options, &block)
  grape_entity/exposure/block_exposure.rb:10:in `value'
    entity.exec_with_object(options, &@block)
  grape_entity/exposure/base.rb:82:in `valid_value'
    value(entity, options) if valid?(entity)
...
(146 additional frame(s) were not displayed)

NoMethodError: undefined method `string_access_level' for nil:NilClass

 经排查,是因为gitlab本身自带了一个Monitoring的项目,它的项目可见性为内部所致。

解决此问题:

  1. 将该自带的项目删除;
  2. 将该项目的可见性改为私有;
  3. 操作数据库修改

这里介绍第三种怎么修改。

查看数据库信息

cat /var/opt/gitlab/gitlab-rails/etc/database.yml

切换到gitlab-psql账号并登录psql

su - gitlab-psql
psql -h /var/opt/gitlab/postgresql -d gitlabhq_production

报错原因为在project_features表中某个project_id为NULL,通过sql语句找出为NULL的projec_id

SELECT id FROM projects WHERE id NOT IN (SELECT project_id AS id FROM project_features WHERE project_id is NOT NULL);

将该project_id插入到project_features表中解决该问题

insert into project_features(project_id,merge_requests_access_level,issues_access_level,wiki_access_level,snippets_access_level,builds_access_level,created_at,updated_at,pages_access_level) VALUES(1,10,10,10,0,10,now(),now(),10);

注意项目权限(access_level)(对应project_features表中pages_access_level的值):

  1. 10 => Guest access

  2. 20 => Reporter access

  3. 30 => Developer access

  4. 40 => Master access

  5. 50 => Owner access # Only valid for groups

最后,引用一下官方文档作为参考:

https://gitlab.com/gitlab-org/gitlab/-/issues/34367 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值