From b9ae421e1a4cb6a6fb802ec08cd59a06c3bf44d6 Mon Sep 17 00:00:00 2001 From: Jeffrey Cross Date: Mon, 7 Aug 2023 15:50:37 -0400 Subject: [PATCH 1/5] Bump celery from 4.2.1 to 5.2.2 in /requirements (#105) Bumps [celery](https://github.com/celery/celery) from 4.2.1 to 5.2.2. - [Release notes](https://github.com/celery/celery/releases) - [Changelog](https://github.com/celery/celery/blob/master/Changelog.rst) - [Commits](https://github.com/celery/celery/compare/v4.2.1...v5.2.2) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/requirements-testing.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements-testing.txt b/requirements/requirements-testing.txt index 628f0fd..02cebb9 100644 --- a/requirements/requirements-testing.txt +++ b/requirements/requirements-testing.txt @@ -1,4 +1,4 @@ -celery<5 +celery>=5.2.2 coverage coveralls django-nose From e4e9c3835154d2d96aa6387e140b130dd67f0017 Mon Sep 17 00:00:00 2001 From: Jeffrey Cross Date: Mon, 7 Aug 2023 15:54:58 -0400 Subject: [PATCH 2/5] Adjust migration (#103) * Adjust a migration to refer to jsonfield using correct v3.1+ nomenclature --- ambition_utils/docs/release_notes.rst | 4 ++++ .../rrule/migrations/0004_rrule_rrule_exclusion_params.py | 5 ++--- ambition_utils/version.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ambition_utils/docs/release_notes.rst b/ambition_utils/docs/release_notes.rst index b40c322..060acf2 100644 --- a/ambition_utils/docs/release_notes.rst +++ b/ambition_utils/docs/release_notes.rst @@ -2,6 +2,10 @@ Release Notes ============= +3.1.11 +------ +* migration adjustment + 3.1.10 ----- * offset() does not consider timezone when reversing. diff --git a/ambition_utils/rrule/migrations/0004_rrule_rrule_exclusion_params.py b/ambition_utils/rrule/migrations/0004_rrule_rrule_exclusion_params.py index 83b9b25..e379355 100644 --- a/ambition_utils/rrule/migrations/0004_rrule_rrule_exclusion_params.py +++ b/ambition_utils/rrule/migrations/0004_rrule_rrule_exclusion_params.py @@ -1,7 +1,6 @@ # Generated by Django 3.2.19 on 2023-06-05 19:55 -import django.contrib.postgres.fields.jsonb -from django.db import migrations +from django.db import migrations, models class Migration(migrations.Migration): @@ -14,6 +13,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='rrule', name='rrule_exclusion_params', - field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=None, null=True), + field=models.JSONField(blank=True, default=None, null=True), ), ] diff --git a/ambition_utils/version.py b/ambition_utils/version.py index be3cf9c..f71ed60 100644 --- a/ambition_utils/version.py +++ b/ambition_utils/version.py @@ -1 +1 @@ -__version__ = '3.1.10' +__version__ = '3.1.11' From 936cc009bd25ad1e6ced13c635fc10895002afbc Mon Sep 17 00:00:00 2001 From: Tyler Neu Date: Mon, 5 Feb 2024 13:53:54 -0600 Subject: [PATCH 3/5] Don't Reset next_occurrence For Cloned Objects (#108) Amend logic determining if object is new by considering last_occurrence so that cloned objects will not be treated as new and have their next_occurrence reset to the first date in the series. Expanded clone_with_day_offset to copy of the source object's next_occurrence, with offset, so that cloned object will not have to processed stale next_occurrence dates to 'catch up'. Added test to flex. --- ambition_utils/rrule/models.py | 6 ++++- ambition_utils/rrule/tests/model_tests.py | 31 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/ambition_utils/rrule/models.py b/ambition_utils/rrule/models.py index 2a4a794..2912ef4 100644 --- a/ambition_utils/rrule/models.py +++ b/ambition_utils/rrule/models.py @@ -351,9 +351,11 @@ def set_date_objects(self): """ Ensure that all the date keys are properly set on all rrule params """ + # A cloned object will not have a primary key but does have a next_occurrence that should not be reset + # to the first date in a series. + is_new = self.pk is None and self.last_occurrence is None # Convert the rrule and exclusion rrule params to properly set date keys - is_new = self.pk is None self.set_date_objects_for_params(self.rrule_params, is_new=is_new) self.set_date_objects_for_params(self.rrule_exclusion_params, is_new=is_new) @@ -470,11 +472,13 @@ def clone_with_day_offset(self, day_offset: int) -> RRule: """ Creates a clone of a passed RRule object with day_offset set. clone() is not called to ensure .id is not set before .save() so offset is applied. + The clone's next_occurrence is set to the offset of this object. :param day_offset: The number of days to offset the clone's start date. Can be negative. """ clone = copy.deepcopy(self) clone.id = None clone.day_offset = day_offset + clone.next_occurrence = clone.offset(clone.next_occurrence) clone.save() return clone diff --git a/ambition_utils/rrule/tests/model_tests.py b/ambition_utils/rrule/tests/model_tests.py index 4a6f665..5cd70e8 100644 --- a/ambition_utils/rrule/tests/model_tests.py +++ b/ambition_utils/rrule/tests/model_tests.py @@ -1614,6 +1614,37 @@ def test_next_occurrences_day_offset(self): self.assertEqual(rrule1.next_occurrence, datetime.datetime(2017, 1, 10)) self.assertEqual(rrule2.next_occurrence, datetime.datetime(2017, 1, 15)) + def test_next_occurrence_clone_with_offset(self): + """ + Cloning an established object with an offset should yield a next_occurrence of the object's with the offset. + """ + # A daily recurrence with a multi-day offset to highlight differences clearly. + rrule1 = G( + RRule, + rrule_params={ + 'freq': rrule.DAILY, + 'interval': 1, + 'dtstart': datetime.datetime(2023, 1, 1), + }, + occurrence_handler_path='ambition_utils.rrule.tests.model_tests.HandlerOne', + ) + + # Many days into the future + with freeze_time('1-10-2023'): + # Catch the recurrence object up. + while rrule1.next_occurrence <= datetime.datetime.now(): + RRule.objects.handle_overdue() + rrule1.refresh_from_db() + self.assertEqual(rrule1.next_occurrence, datetime.datetime(2023, 1, 11)) + + # Create a clone with an offset and assert that the clone's next occurrence is 1/11 -5 = 1/6. + rrule2 = rrule1.clone_with_day_offset(day_offset=-5) + self.assertEqual(rrule2.next_occurrence, datetime.datetime(2023, 1, 6)) + + # First object is unchanged + rrule1.refresh_from_db() + self.assertEqual(rrule1.next_occurrence, datetime.datetime(2023, 1, 11)) + class RRuleWithExclusionTest(TestCase): def test_exclusion(self): From 4bdb23411b397df17dd210f1c525f54cece4c5c0 Mon Sep 17 00:00:00 2001 From: Tyler Neu Date: Fri, 9 Feb 2024 11:15:13 -0600 Subject: [PATCH 4/5] Release bump --- ambition_utils/docs/release_notes.rst | 4 ++++ ambition_utils/version.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ambition_utils/docs/release_notes.rst b/ambition_utils/docs/release_notes.rst index 060acf2..d55c830 100644 --- a/ambition_utils/docs/release_notes.rst +++ b/ambition_utils/docs/release_notes.rst @@ -2,6 +2,10 @@ Release Notes ============= +3.1.12 +------ +* clone_with_day_offset now returns an object with the next_occurrence of the source object. + 3.1.11 ------ * migration adjustment diff --git a/ambition_utils/version.py b/ambition_utils/version.py index f71ed60..1e6263a 100644 --- a/ambition_utils/version.py +++ b/ambition_utils/version.py @@ -1 +1 @@ -__version__ = '3.1.11' +__version__ = '3.1.12' From b6ecb1e63df80510bf50e239f598c89e086467c6 Mon Sep 17 00:00:00 2001 From: Tyler Neu Date: Fri, 9 Feb 2024 13:41:37 -0600 Subject: [PATCH 5/5] Updated release note for clairity --- ambition_utils/docs/release_notes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ambition_utils/docs/release_notes.rst b/ambition_utils/docs/release_notes.rst index d55c830..1cd414b 100644 --- a/ambition_utils/docs/release_notes.rst +++ b/ambition_utils/docs/release_notes.rst @@ -4,7 +4,7 @@ Release Notes 3.1.12 ------ -* clone_with_day_offset now returns an object with the next_occurrence of the source object. +* RRule clones will now retain the next_occurrence of the source. 3.1.11 ------