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

Fix TestCustomQuery test that fails at beginning of year #6853

Merged
merged 2 commits into from
Jan 6, 2025

Conversation

willkg
Copy link
Contributor

@willkg willkg commented Jan 2, 2025

The index name template uses week number and when we calculate the expected index names by adding 7 days to figure out the next week number, that doesn't work at the beginning of the year when the previous year includes a partial week.

This fixes that by changing the code to figure out week numbers by incrementing by one day, generating index names, throwing those in a set, and then turning that into a sorted list.

The index name template uses week number and when we calculate
the expected index names by adding 7 days to figure out the next week
number, that doesn't work at the beginning of the year when the previous
year includes a partial week.

This fixes that by changing the code to figure out week numbers by
incrementing by one day, generating index names, throwing those in a
set, and then turning that into a sorted list.
@willkg willkg requested a review from a team as a code owner January 2, 2025 18:20
# the index name is based on the week number and this handles the
# end-of-year/beginning-of-year case correctly.
for i in range(7):
indices.add((now - datetime.timedelta(days=i)).strftime(template))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old version used now and now–7d as the index names. The new version only goes back to now-6d. I can't tell whether that's intentional or not, or whether it matters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops--I forgot that range is open-ended.

import datetime

def old_way(template, date):
    return [
        (date - datetime.timedelta(days=7)).strftime(template),
        date.strftime(template)
    ]

def new_way(template, date):
    indices = set()
    # NOTE(willkg): we have to build the list of indices this way because
    # the index name is based on the week number and this handles the
    # end-of-year/beginning-of-year case correctly.
    for i in range(7):
        indices.add((date - datetime.timedelta(days=i)).strftime(template))
    return sorted(indices)


template = "socorro%Y%W"

deltas = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

for i in deltas:
    date = datetime.date.today() + datetime.timedelta(days=i)
    print(f"{date}:  old way:{old_way(template, date)}  new way: {new_way(template, date)}")
2024-12-27:  old way:['socorro202451', 'socorro202452']  new way: ['socorro202451', 'socorro202452']
2024-12-28:  old way:['socorro202451', 'socorro202452']  new way: ['socorro202451', 'socorro202452']
2024-12-29:  old way:['socorro202451', 'socorro202452']  new way: ['socorro202452']
2024-12-30:  old way:['socorro202452', 'socorro202453']  new way: ['socorro202452', 'socorro202453']
2024-12-31:  old way:['socorro202452', 'socorro202453']  new way: ['socorro202452', 'socorro202453']
2025-01-01:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-02:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-03:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-04:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-05:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202453', 'socorro202500']
2025-01-06:  old way:['socorro202453', 'socorro202501']  new way: ['socorro202453', 'socorro202500', 'socorro202501']
2025-01-07:  old way:['socorro202453', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-08:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-09:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-10:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-11:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-12:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202501']
2025-01-13:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']
2025-01-14:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']
2025-01-15:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']
2025-01-16:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']

@willkg
Copy link
Contributor Author

willkg commented Jan 6, 2025

^^^ That fixes the index names generation:

2024-12-27:  old way:['socorro202451', 'socorro202452']  new way: ['socorro202451', 'socorro202452']
2024-12-28:  old way:['socorro202451', 'socorro202452']  new way: ['socorro202451', 'socorro202452']
2024-12-29:  old way:['socorro202451', 'socorro202452']  new way: ['socorro202451', 'socorro202452']
2024-12-30:  old way:['socorro202452', 'socorro202453']  new way: ['socorro202452', 'socorro202453']
2024-12-31:  old way:['socorro202452', 'socorro202453']  new way: ['socorro202452', 'socorro202453']
2025-01-01:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-02:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-03:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-04:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-05:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-06:  old way:['socorro202453', 'socorro202501']  new way: ['socorro202453', 'socorro202500', 'socorro202501']
2025-01-07:  old way:['socorro202453', 'socorro202501']  new way: ['socorro202453', 'socorro202500', 'socorro202501']
2025-01-08:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-09:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-10:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-11:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-12:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-13:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']
2025-01-14:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']
2025-01-15:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']
2025-01-16:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']

@willkg willkg requested a review from smarnach January 6, 2025 13:31
@willkg willkg added this pull request to the merge queue Jan 6, 2025
@willkg
Copy link
Contributor Author

willkg commented Jan 6, 2025

Thank you!

Merged via the queue into main with commit f87219a Jan 6, 2025
1 check passed
@willkg willkg deleted the fix-testcustomquery-test branch January 6, 2025 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants