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

[#65866] NoMethodError in GET::API::V3::Queries::QueriesAPI#/queries/:id/

Dombi Attila38488e2993d4
diff --git a/app/models/journal/timestamps.rb b/app/models/journal/timestamps.rb
index ca0d55d4835..0e3aa93ccb0 100644
--- a/app/models/journal/timestamps.rb
+++ b/app/models/journal/timestamps.rb
@@ -72,6 +72,12 @@ module Journal::Timestamps
timestamp = timestamp.to_time if timestamp.kind_of? Timestamp
timestamp = timestamp.in_time_zone if timestamp.kind_of? DateTime
+ # By default rails will chop off the timezone from a date time parameter and just let
+ # postgresql to use the db session's timezone, which can be different from UTC.
+ # Pass the timestamp as a string including the UTC timezone explicitly, to the query
+ # in order to force postgres to use UTC instead of the session's timezone.
+
+ timestamp = timestamp.utc.to_s
where(OpenProject::SqlSanitization.sanitize("validity_period @> timestamp with time zone :timestamp", timestamp:))
end
end
diff --git a/spec/models/journal/timestamps_spec.rb b/spec/models/journal/timestamps_spec.rb
index a2bf4bd43f9..42be6f4022a 100644
--- a/spec/models/journal/timestamps_spec.rb
+++ b/spec/models/journal/timestamps_spec.rb
@@ -94,6 +94,17 @@ RSpec.describe Journal::Timestamps do
end
end
+ describe "when ensuring UTC is passed to the timestamp where condition" do
+ it "converts the timestamp to UTC in the generated SQL" do
+ sql = Time.use_zone("America/New_York") do
+ est_time = Time.zone.parse("2022-08-01 11:30:00")
+ Journal.at_timestamp(est_time).to_sql
+ end
+ expect(sql)
+ .to include(/validity_period @> timestamp with time zone '2022-08-01 15:30:00 UTC'/)
+ end
+ end
+
describe "when there are journals for Monday, Wednesday, and Friday" do
let(:before_monday) { "2022-01-01".to_datetime }
let(:monday) { "2022-08-01".to_datetime }