Changes update_column to update_attributes in ProjectTreeRestorer#restore_project by using timeless to maintain the current timestamps
What does this MR do?
From https://gitlab.com/gitlab-org/gitlab-ce/issues/47765#note_81266830 :
@stanhu
It appears that this project was created from a template, which is effectively just a project export bundled with GitLab, that we import when someone creates a new project from that template.
The "Create from template" form at https://gitlab.com/projects/new has a few form fields, including
visibility_level
, that end up inProjects::CreateFromTemplateService
asparams
, are passed along toGitlabProjectsImportService
asoverride_params
, stored onproject.import_data
, read by the asynchronous-running import logic, and applied on the project along with the data from the actual exported JSON using@project.update_columns
.
The issue with this is that
params
from HTTP forms always have string values, even if they are actually meant to be numeric, which means thatoverride_params
will look like{ "visibility_level" => "0" }
.Project#visibility_level=
andProject#update_attributes
automatically convert this value to an integer so that@project.visibility_level
will end up as0
, butProject#update_columns
is too low level for that. It will directly update@project.visibility_level
without conversion, so it ends up as"0"
, and will pass the string value along to the DB. The DB is smart enough to perform the conversion itself so that we end up with0
in the DB, but until the model is reloaded,@project.visibility_level
will be"0"
.
I think we should be using #update_attributes
instead of #update_columns
in Gitlab::ImportExport::ProjectTreeRestorer#restore_project
@jameslopez
What do you think? Do you remember why you used #update_columns
in https://gitlab.com/gitlab-org/gitlab-ce/commit/2174e37845f6865c20ba94da5520c8d9e874998f#07953e6bce219868b76e93d653174a723292477a_75_74, and #update
before that, rather than #update_attributes
?
From https://gitlab.com/gitlab-org/gitlab-ce/issues/47765#note_82226315 :
I can't remember exactly, but probably it has to do with ignoring
updated_at
(so it preserves old timestamps) and not calling callbacks...
This MR aims to change update_column
usage in ProjectTreeRestorer#restore_project
by update_attributes
with the usage of Gitlab::Timeless
to keep timestamps from being updated
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary -
Documentation created/updated -
Tests added for this feature/bug -
Conforms to the code review guidelines -
Conforms to the merge request performance guidelines -
Conforms to the style guides -
Conforms to the database guides
What are the relevant issue numbers?
Closes #47765 (closed)