Skip to content

Commit

Permalink
fix: duplicate reports when run for past years
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Oct 18, 2024
1 parent 09fb099 commit a93eb05
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions osf/metrics/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
assert 'report_date' in cls.UNIQUE_TOGETHER_FIELDS, f'DailyReport subclasses must have "report_date" in UNIQUE_TOGETHER_FIELDS (on {cls.__qualname__}, got {cls.UNIQUE_TOGETHER_FIELDS})'

def save(self, *args, **kwargs):
if self.timestamp is None:
self.timestamp = self.report_date
super().save(*args, **kwargs)

class Meta:
abstract = True
dynamic = metrics.MetaField('strict')
Expand Down Expand Up @@ -101,6 +106,12 @@ def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
assert 'report_yearmonth' in cls.UNIQUE_TOGETHER_FIELDS, f'MonthlyReport subclasses must have "report_yearmonth" in UNIQUE_TOGETHER_FIELDS (on {cls.__qualname__}, got {cls.UNIQUE_TOGETHER_FIELDS})'

def save(self, *args, **kwargs):
if self.timestamp is None:
self.timestamp = self.report_yearmonth.target_month()
super().save(*args, **kwargs)



@receiver(metrics_pre_save)
def set_report_id(sender, instance, **kwargs):
Expand Down

0 comments on commit a93eb05

Please sign in to comment.