Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Do not assign time zone, when there is no user

Klaus Zanders359bb5699379
diff --git a/modules/costs/app/services/time_entries/set_attributes_service.rb b/modules/costs/app/services/time_entries/set_attributes_service.rb
index 65cbe60e3e2..2da2362665e 100644
--- a/modules/costs/app/services/time_entries/set_attributes_service.rb
+++ b/modules/costs/app/services/time_entries/set_attributes_service.rb
@@ -45,7 +45,7 @@ module TimeEntries
# move the timezone from the user
model.change_by_system do
- model.time_zone = model.user.time_zone.name
+ model.time_zone = model.user.time_zone.name if model.user
end
# Set start time for ongoing time entries
diff --git a/modules/costs/spec/services/time_entries/set_attributes_service_spec.rb b/modules/costs/spec/services/time_entries/set_attributes_service_spec.rb
index f04a650832b..bc7ea05c1e5 100644
--- a/modules/costs/spec/services/time_entries/set_attributes_service_spec.rb
+++ b/modules/costs/spec/services/time_entries/set_attributes_service_spec.rb
@@ -135,6 +135,26 @@ RSpec.describe TimeEntries::SetAttributesService, type: :model do
expect(attributes_of_interest)
.to eql(expected)
end
+
+ context "with an existing record and params including an empty user" do
+ let(:params) do
+ {
+ user_id: ""
+ }
+ end
+
+ before do
+ allow(time_entry_instance).to receive(:new_record?).and_return(false)
+ end
+
+ it "runs correctly and not raise an error trying to assign the timezone (Reggression #63843)" do
+ expect do
+ subject
+ end.not_to raise_error
+
+ expect(time_entry_instance.user).to be_nil
+ end
+ end
end
context "with a user with a defined timezone" do