Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When time traveling, deleted reports are shown after their deletion date #2997

Closed
fniessink opened this issue Dec 8, 2021 · 0 comments · Fixed by #2998
Closed

When time traveling, deleted reports are shown after their deletion date #2997

fniessink opened this issue Dec 8, 2021 · 0 comments · Fixed by #2998
Assignees
Labels
Bug Something isn't working
Projects

Comments

@fniessink
Copy link
Member

fniessink commented Dec 8, 2021

For example, a report deleted at December 1st, 2021 is visible when time traveling to December 2nd, 2021. When time traveling to the current date, the report is not shown.

The problem is that in latest_reports, the distinct report_uuids are retrieved while ignoring deleted reports. This means that if a report is deleted before the max_iso_timestamp, the previous undeleted report is retrieved.

def latest_reports(database: Database, data_model: dict, max_iso_timestamp: str = "") -> list[Report]:
    """Return the latest, undeleted, reports in the reports collection."""
    if max_iso_timestamp and max_iso_timestamp < iso_timestamp():
        report_filter = dict(deleted=DOES_NOT_EXIST, timestamp={"$lt": max_iso_timestamp})
        report_uuids = database.reports.distinct("report_uuid", report_filter)
        reports = []
        for report_uuid in report_uuids:
            report_filter["report_uuid"] = report_uuid
            report_dict = database.reports.find_one(report_filter, sort=TIMESTAMP_DESCENDING)
            report = Report(data_model, report_dict)
            reports.append(report)
    else:
        report_dicts = database.reports.find({"last": True, "deleted": DOES_NOT_EXIST})
        reports = [Report(data_model, report_dict) for report_dict in report_dicts]
    return reports

A simple solution is to retrieve all report_uuids, regardless of deletion status and then filter the deleted reports in the for loop:

def latest_reports(database: Database, data_model: dict, max_iso_timestamp: str = "") -> list[Report]:
    """Return the latest, undeleted, reports in the reports collection."""
    if max_iso_timestamp and max_iso_timestamp < iso_timestamp():
        report_filter = dict(timestamp={"$lt": max_iso_timestamp})
        report_uuids = database.reports.distinct("report_uuid", report_filter)
        reports = []
        for report_uuid in report_uuids:
            report_filter["report_uuid"] = report_uuid
            report_dict = database.reports.find_one(report_filter, sort=TIMESTAMP_DESCENDING)
            if report_dict.get("deleted"):
                continue
            report = Report(data_model, report_dict)
            reports.append(report)
    else:
        report_dicts = database.reports.find({"last": True, "deleted": DOES_NOT_EXIST})
        reports = [Report(data_model, report_dict) for report_dict in report_dicts]
    return reports
@fniessink fniessink added the Bug Something isn't working label Dec 8, 2021
@fniessink fniessink added this to Backlog in Backlog via automation Dec 8, 2021
@fniessink fniessink moved this from Backlog to Ready in Backlog Dec 8, 2021
@fniessink fniessink moved this from Ready to Development in progress (max 4) in Backlog Dec 8, 2021
@fniessink fniessink self-assigned this Dec 8, 2021
fniessink added a commit that referenced this issue Dec 8, 2021
fniessink added a commit that referenced this issue Dec 8, 2021
…their deletion date. (#2998)

* When time traveling, *Quality-time* would show deleted reports after their deletion date. Fixes #2997.
@fniessink fniessink moved this from Development in progress (max 4) to Reviewing in progress in Backlog Dec 8, 2021
@fniessink fniessink moved this from Reviewing in progress to Merged in Backlog Dec 8, 2021
@fniessink fniessink moved this from Merged to Release candidate released in Backlog Dec 9, 2021
@fniessink fniessink moved this from Release candidate released to Released in Backlog Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Backlog
Released
1 participant