Commit 8b9b37f6 authored by Sean McGivern's avatar Sean McGivern

Fix upcoming milestone for far-future due dates

`NOW()` is a timestamp, with a maximum year (in Postgres) 294276 AD.

`milestones.due_date` is a date with a maximum year (again, in Postgres)
of 5874897 AD.

If there is a due date past the limit for the timestamp, comparing the
two will fail with:
    ERROR:  date out of range for timestamp

We also need to add validations to keep the due dates sensible, but for
now we can simply use `CURRENT_DATE` instead of `NOW()`, so the types
match with no coercion needed.
parent 8a49eeed
...@@ -149,7 +149,7 @@ class Milestone < ActiveRecord::Base ...@@ -149,7 +149,7 @@ class Milestone < ActiveRecord::Base
def self.upcoming_ids(projects, groups) def self.upcoming_ids(projects, groups)
rel = unscoped rel = unscoped
.for_projects_and_groups(projects, groups) .for_projects_and_groups(projects, groups)
.active.where('milestones.due_date > NOW()') .active.where('milestones.due_date > CURRENT_DATE')
if Gitlab::Database.postgresql? if Gitlab::Database.postgresql?
rel.order(:project_id, :group_id, :due_date).select('DISTINCT ON (project_id, group_id) id') rel.order(:project_id, :group_id, :due_date).select('DISTINCT ON (project_id, group_id) id')
...@@ -161,7 +161,7 @@ class Milestone < ActiveRecord::Base ...@@ -161,7 +161,7 @@ class Milestone < ActiveRecord::Base
ON milestones.project_id <=> earlier_milestones.project_id ON milestones.project_id <=> earlier_milestones.project_id
AND milestones.group_id <=> earlier_milestones.group_id AND milestones.group_id <=> earlier_milestones.group_id
AND milestones.due_date > earlier_milestones.due_date AND milestones.due_date > earlier_milestones.due_date
AND earlier_milestones.due_date > NOW() AND earlier_milestones.due_date > CURRENT_DATE
AND earlier_milestones.state = 'active' AND earlier_milestones.state = 'active'
HEREDOC HEREDOC
......
---
title: Fix upcoming milestone when there are milestones with far-future due dates
merge_request:
author:
type: fixed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment