File lock button incorrectly shown in UI when more than 100 files locked in project, due to query limit.
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Summary
When a locked file is selected in the repository browser, the lock status is determined by searching for the file in the results from the following query, which is limited to the 101 most recent entries in the path_locks
table. This means if there are > 100 locked files in the project, some files will be incorrectly determined as being unlocked, and the Lock button displayed instead of the Unlock button.
SELECT "path_locks".* FROM "path_locks" WHERE "path_locks"."project_id" = <project_id> ORDER BY "path_locks"."id" DESC LIMIT 101;
This prevents the file from being Unlocked.
Reproduced in version 17.3.3. Assumed applicable to gitlab.com.
Reported by customer (ZD internal link).
Workaround
The Code, Locked files page correctly displays all locked files, and allows them to be unlocked.
Steps to reproduce
- Create a project
root/file-locking-bug
with 121 files namedfiles/100.txt
tofiles/220.txt
- Using the rails console, lock all of the files:
include API::Helpers::GraphqlHelpers
current_user=User.find_by_username('root')
query="mutation toggleLock($projectPath: ID!, $filePath: String!, $lock: Boolean!) { projectSetLocked( input: {projectPath: $projectPath, filePath: $filePath, lock: $lock} ) { project { id pathLocks { nodes { id path __typename } __typename } __typename } errors __typename }}"
for i in 100..220 do
variables={filePath: "files/#{i}.txt", projectPath: "root/file-locking-bug", lock: true}
run_graphql!(query: query, context: {current_user: current_user}, variables: variables)
end
- Go to Project, Code, Locked files in the UI and confirm 121 locked files are listed.
- From the repository browser go to the file
files/220.txt
. Confirm that the Unlock button is displayed, as expected when the file is locked. - From the repository browser go to the file
files/100.txt
. Confirm that the Lock button is displayed, despite the file being locked.
Example Project
What is the current bug behavior?
Some locked files incorrectly present the Lock button when the file is viewed in the UI.
What is the expected correct behavior?
All locked files should display the Unlock button.
Relevant logs and/or screenshots
Query run when file 100.txt page refreshed:
LOG: execute <unnamed>: /*application:web,correlation_id:01J8RF49NZPWAZC7XV919PC006,endpoint_id:GraphqlController#execute,db_config_name:main*/ SELECT "path_locks".* FROM "path_locks" WHERE "path_locks"."project_id" = 47 ORDER BY "path_locks"."id" DESC LIMIT 101
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`sudo gitlab-rake gitlab:env:info\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`) (For installations from source run and paste the output of: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of: \\\\\\\\\\\\\\\`sudo gitlab-rake gitlab:check SANITIZE=true\\\\\\\\\\\\\\\`) (For installations from source run and paste the output of: \\\\\\\\\\\\\\\`sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true\\\\\\\\\\\\\\\`) (we will only investigate if the tests are passing)