-
Notifications
You must be signed in to change notification settings - Fork 464
fix get unique timezones #896
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
base: main
Are you sure you want to change the base?
Conversation
155d83e
to
aabbaad
Compare
Please run pre-commit on |
@cclauss updated |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #896 +/- ##
==========================================
- Coverage 88.19% 87.99% -0.20%
==========================================
Files 32 32
Lines 1008 1008
Branches 105 105
==========================================
- Hits 889 887 -2
- Misses 101 102 +1
- Partials 18 19 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@alirafiei75 please take a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get additional tests for this?
@auvipy can you suggest what additional tests you want here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are failing tests now, can you fix them?
the previous query did not actually get distinct timezones
The rebase didn’t work. Please make it errorless again |
this tested for string timezones, which were not possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing the tests?
it's the same test as the one below |
@@ -1663,31 +1678,6 @@ def setup_method(self): | |||
def teardown_method(self): | |||
patch.stopall() | |||
|
|||
@patch("django_celery_beat.schedulers.aware_now") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add more tests which also improve the test coverage? and there is no regression introduced?
if you're referring to the codecov note, then i would guess it's b/c the tests only run with sqlite. can you confirm? if so, i don't have have the bandwidth to update the test suite to also run a build with non-sqlite (eg. postgres). i can remove the sqlite/non-sqlite conditional in that code even though it'll be less performant, but i think it'll increase the codecov by virtue of not having a non-tested branch re: regressions, there are existing tests from the original PR that introduced this change that should cover regressions. this change is a performance improvement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses the issue where distinct timezones were not actually being retrieved, and updates related tests to use timezone-aware datetime
.
- Refactors scheduler to introduce
_get_unique_timezones
and adjust_get_crontab_exclude_query
and_get_timezone_offset
to work withZoneInfo
- Adds a new
test_get_unique_timezones
to verify unique timezone retrieval and converts test timestamps to UTC-aware datetimes - Updates imports and annotations to support the new implementations
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
t/unit/test_schedulers.py | Replaced datetime.utcnow() with datetime.now(dt_timezone.utc) and added test_get_unique_timezones |
django_celery_beat/schedulers.py | Added _get_unique_timezones , updated _get_crontab_exclude_query and _get_timezone_offset , and imported connection |
Comments suppressed due to low confidence (2)
django_celery_beat/schedulers.py:390
- The docstring still refers to
timezone_name
even though the parameter is nowtimezone
(aZoneInfo
). Update the docstring to match the new parameter name and type for clarity.
def _get_timezone_offset(self, timezone: ZoneInfo) -> int:
t/unit/test_schedulers.py:1230
- [nitpick] The test docstring says it returns a "list" of timezones but actually asserts against a
set
. Consider updating the docstring to say "set" for consistency.
Test that get unique timezones returns a list of unique timezones
return CrontabSchedule.objects.values_list( | ||
'timezone', flat=True | ||
).distinct() | ||
def _get_unique_timezones(self) -> set[ZoneInfo]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method currently returns raw timezone name strings but declares a return type of set[ZoneInfo]
and tests expect ZoneInfo
instances. Consider mapping each string to ZoneInfo
, e.g. set(ZoneInfo(tz) for tz in ...)
, to ensure the returned values match the signature and test expectations.
Copilot uses AI. Check for mistakes.
@@ -330,14 +332,14 @@ def _get_crontab_exclude_query(self): | |||
# Handle each timezone specifically | |||
*[ | |||
When( | |||
timezone=timezone_name, | |||
timezone=timezone, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lookup uses a ZoneInfo
object for the timezone
field, but the database stores timezones as strings. Convert to str(timezone)
or timezone.key
so the ORM lookup matches the stored values.
timezone=timezone, | |
timezone=str(timezone), |
Copilot uses AI. Check for mistakes.
the previous query did not actually get distinct timezones