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: duplicate reports when run for past years #10781

Draft
wants to merge 1 commit into
base: feature/insti-dash-improv
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading