新安装的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的项目,它的项目可见性为内部所致。
解决此问题:
- 将该自带的项目删除;
- 将该项目的可见性改为私有;
- 操作数据库修改
这里介绍第三种怎么修改。
查看数据库信息
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的值
):
-
10 => Guest access
-
20 => Reporter access
-
30 => Developer access
-
40 => Master access
-
50 => Owner access # Only valid for groups
最后,引用一下官方文档作为参考:
https://gitlab.com/gitlab-org/gitlab/-/issues/34367