mirror of
https://github.com/makeplane/plane.git
synced 2026-08-29 10:08:51 +02:00
[WEB-8477] fix(api): filter "Updated At" by updated_at column, not created_at (#9514)
filter_updated_at() passed `created_at__date` as the date term in both its GET and POST branches, so filtering by "Updated At" actually filtered on the creation date. Work items updated today but created earlier never appeared under "Updated At -> is -> today", and the two filters returned identical result sets. Re-raise of community PR #9323 by @sanjibani, which is approved-ready but cannot merge because the CLA is unsigned. Original patch and tests carried over unchanged apart from the two fixes below; credit for the fix is theirs. Adjustments made while porting: - test_get_method_targets_updated_at_column asserted the exact key "updated_at__date", but date_filter's single-value branch appends a lookup suffix ("updated_at__date__contains"), so the assertion always failed. Match on the key prefix instead. - Added the missing trailing newline to the new test file. Verified on a local canary build: with one work item created 2020-01-01 but updated today, `?updated_at=2026-07-01;after` now returns 5 while `?created_at=2026-07-01;after` returns 4 — previously both returned 4. Unit tests pass (5); 4 of the 5 fail without the source change. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
53
apps/api/plane/tests/unit/utils/test_issue_filters.py
Normal file
53
apps/api/plane/tests/unit/utils/test_issue_filters.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# Copyright (c) 2023-present Plane Software, Inc. and contributors
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
# See the LICENSE file for details.
|
||||
|
||||
import pytest
|
||||
|
||||
from plane.utils.issue_filters import filter_updated_at
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class TestFilterUpdatedAt:
|
||||
"""Regression test for the "Updated At" filter bug — the filter was
|
||||
applying to the `created_at` column instead of `updated_at`, so work
|
||||
items updated today but created earlier never showed up under
|
||||
`Updated At -> is -> today`. See issue #9316."""
|
||||
|
||||
def test_get_method_targets_updated_at_column(self):
|
||||
issue_filter = {}
|
||||
params = {"updated_at": "2026-06-26"}
|
||||
filter_updated_at(params, issue_filter, method="GET")
|
||||
# The filter must key on updated_at, not created_at. A bare date goes through
|
||||
# date_filter's single-value branch, which appends a lookup suffix
|
||||
# (updated_at__date__contains), so match on the prefix rather than the exact key.
|
||||
assert any(key.startswith("updated_at__date") for key in issue_filter)
|
||||
assert not any("created_at" in key for key in issue_filter)
|
||||
|
||||
def test_get_method_with_csv_targets_updated_at_column(self):
|
||||
issue_filter = {}
|
||||
params = {"updated_at": "2026-06-25,2026-06-26"}
|
||||
filter_updated_at(params, issue_filter, method="GET")
|
||||
assert all("updated_at" in key for key in issue_filter)
|
||||
assert not any("created_at" in key for key in issue_filter)
|
||||
|
||||
def test_post_method_targets_updated_at_column(self):
|
||||
issue_filter = {}
|
||||
params = {"updated_at": ["2026-06-26"]}
|
||||
filter_updated_at(params, issue_filter, method="POST")
|
||||
assert all("updated_at" in key for key in issue_filter)
|
||||
assert not any("created_at" in key for key in issue_filter)
|
||||
|
||||
def test_get_method_with_prefix_targets_updated_at_column(self):
|
||||
issue_filter = {}
|
||||
params = {"updated_at": "2026-06-26"}
|
||||
filter_updated_at(params, issue_filter, method="GET", prefix="cycle_issue__")
|
||||
keys = list(issue_filter)
|
||||
assert any("cycle_issue__updated_at" in k for k in keys)
|
||||
assert not any("created_at" in k for k in keys)
|
||||
|
||||
def test_empty_get_filter_is_noop(self):
|
||||
issue_filter = {}
|
||||
params = {"updated_at": ""}
|
||||
filter_updated_at(params, issue_filter, method="GET")
|
||||
assert issue_filter == {}
|
||||
@@ -231,14 +231,14 @@ def filter_updated_at(params, issue_filter, method, prefix=""):
|
||||
if len(updated_ats) and "" not in updated_ats:
|
||||
date_filter(
|
||||
issue_filter=issue_filter,
|
||||
date_term=f"{prefix}created_at__date",
|
||||
date_term=f"{prefix}updated_at__date",
|
||||
queries=updated_ats,
|
||||
)
|
||||
else:
|
||||
if params.get("updated_at", None) and len(params.get("updated_at")):
|
||||
date_filter(
|
||||
issue_filter=issue_filter,
|
||||
date_term=f"{prefix}created_at__date",
|
||||
date_term=f"{prefix}updated_at__date",
|
||||
queries=params.get("updated_at", []),
|
||||
)
|
||||
return issue_filter
|
||||
|
||||
Reference in New Issue
Block a user