Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions bugbug/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import itertools
import math
import re
from datetime import datetime
from datetime import datetime, timezone
from logging import INFO, basicConfig, getLogger
from typing import Iterable, Iterator, NewType
from urllib.parse import urlencode
Expand Down Expand Up @@ -360,7 +360,7 @@ def get_product_component_count(months: int = 12) -> dict[str, int]:
`{product}::{component}`) and the value of the number of bugs for the
given full components. Full component with 0 bugs are returned.
"""
since = datetime.utcnow() - relativedelta(months=months)
since = datetime.now(timezone.utc) - relativedelta(months=months)

# Base params
params = {
Expand Down
4 changes: 2 additions & 2 deletions bugbug/models/accessibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.

import logging
from datetime import datetime
from datetime import datetime, timezone

import xgboost
from dateutil.relativedelta import relativedelta
Expand Down Expand Up @@ -94,7 +94,7 @@ def __download_older_access_bugs(months: int) -> None:

This function provides an option to extend the dataset used for model training by including older bugs.
"""
lookup_start_date = datetime.utcnow() - relativedelta(months=months)
lookup_start_date = datetime.now(timezone.utc) - relativedelta(months=months)
params = {
"f1": "creation_ts",
"o1": "greaterthan",
Expand Down
10 changes: 8 additions & 2 deletions bugbug/models/backout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.

import logging
from datetime import datetime
from datetime import datetime, timezone

import dateutil.parser
import xgboost
from dateutil import tz
from dateutil.relativedelta import relativedelta
from imblearn.pipeline import Pipeline as ImblearnPipeline
from imblearn.under_sampling import RandomUnderSampler
Expand Down Expand Up @@ -116,12 +117,17 @@ def __init__(self, lemmatization=False, bug_data=False):
def get_labels(self):
classes = {}

two_years_and_six_months_ago = datetime.utcnow() - relativedelta(
two_years_and_six_months_ago = datetime.now(timezone.utc) - relativedelta(
years=2, months=6
)

for commit_data in repository.get_commits():
pushdate = dateutil.parser.parse(commit_data["pushdate"])
if pushdate.tzinfo is None:
pushdate = pushdate.replace(tzinfo=tz.UTC)
else:
pushdate = pushdate.astimezone(tz.UTC)
Comment on lines 125 to +129

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Simplified:

Suggested change
pushdate = dateutil.parser.parse(commit_data["pushdate"])
if pushdate.tzinfo is None:
pushdate = pushdate.replace(tzinfo=tz.UTC)
else:
pushdate = pushdate.astimezone(tz.UTC)
pushdate = datetime.fromisoformat(commit_data["pushdate"])
pushdate = pushdate.replace(tzinfo=pushdate.tzinfo or timezone.UTC)


if pushdate < two_years_and_six_months_ago:
continue

Expand Down
14 changes: 9 additions & 5 deletions bugbug/models/regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import itertools
import logging
from datetime import datetime
from datetime import datetime, timezone

import dateutil.parser
import numpy as np
Expand Down Expand Up @@ -188,7 +188,9 @@ def get_labels(self):
push_date = dateutil.parser.parse(commit_data["pushdate"])

# Skip commits used for the evaluation phase.
if push_date > datetime.utcnow() - relativedelta(months=EVALUATION_MONTHS):
if push_date > datetime.now(timezone.utc) - relativedelta(
months=EVALUATION_MONTHS
):
continue

node = commit_data["node"]
Expand All @@ -203,15 +205,15 @@ def get_labels(self):
# In the future, we might want to re-evaluate this limit (e.g. extend ), but we
# have to be careful (using too old patches might cause worse results as patch
# characteristics evolve over time).
if push_date < datetime.utcnow() - relativedelta(years=2):
if push_date < datetime.now(timezone.utc) - relativedelta(years=2):
continue

# We remove the last 3 months, as there could be regressions which haven't been
# filed yet. While it is true that some regressions might not be found for a long
# time, more than 3 months seems overly conservative.
# There will be some patches we currently add to the clean set and will later move
# to the regressor set, but they are a very small subset.
if push_date > datetime.utcnow() - relativedelta(months=3):
if push_date > datetime.now(timezone.utc) - relativedelta(months=3):
continue

classes[node] = 0
Expand Down Expand Up @@ -267,7 +269,9 @@ def evaluation(self) -> None:
push_date = dateutil.parser.parse(commit_data["pushdate"])

# Use the past two months of data (make sure it is not also used for training!).
if push_date < datetime.utcnow() - relativedelta(months=EVALUATION_MONTHS):
if push_date < datetime.now(timezone.utc) - relativedelta(
months=EVALUATION_MONTHS
):
continue

commits.append(commit_data)
Expand Down
6 changes: 3 additions & 3 deletions bugbug/phabricator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import itertools
import logging
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Collection, Iterator, NewType

import tenacity
Expand Down Expand Up @@ -298,9 +298,9 @@ def get_pending_review_time(rev: RevisionDict) -> timedelta | None:
)

if last_exclusion_end_date is not None:
return datetime.utcnow() - last_exclusion_end_date
return datetime.now(timezone.utc) - last_exclusion_end_date
else:
return datetime.utcnow() - creation_date
return datetime.now(timezone.utc) - creation_date


def fetch_diff_from_url(
Expand Down
6 changes: 3 additions & 3 deletions bugbug/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import subprocess
import sys
import threading
from datetime import datetime
from datetime import datetime, timezone
from functools import lru_cache
from typing import Collection, Iterable, Iterator, NewType, Set, Union

Expand Down Expand Up @@ -903,9 +903,9 @@ def hg_log(
assert b" " in rev[6]
pushdate_timestamp = rev[6].split(b" ", 1)[0]
if pushdate_timestamp != b"0":
pushdate = datetime.utcfromtimestamp(float(pushdate_timestamp))
pushdate = datetime.fromtimestamp(float(pushdate_timestamp), timezone.utc)
else:
pushdate = datetime.utcnow()
pushdate = datetime.now(timezone.utc)

bug_id = int(rev[3].decode("ascii")) if rev[3] else None

Expand Down
22 changes: 17 additions & 5 deletions functions/sync-review-comments-db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.

import enum
from datetime import datetime
from datetime import datetime, timedelta, timezone
from typing import List, Optional

from sqlalchemy import ForeignKey, ScalarResult, UniqueConstraint, func, select
from sqlalchemy import (
DateTime,
ForeignKey,
ScalarResult,
UniqueConstraint,
func,
select,
)
from sqlalchemy.orm import (
DeclarativeBase,
Mapped,
Expand Down Expand Up @@ -73,14 +80,19 @@ class ReviewRequest(Base):
sequence: Mapped[int]

# pylint:disable=not-callable
created_at: Mapped[datetime] = mapped_column(server_default=func.now())
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
updated_at: Mapped[datetime] = mapped_column(
server_default=func.now(), server_onupdate=func.now()
DateTime(timezone=True),
nullable=False,
server_default=func.now(),
server_onupdate=func.now(),
Comment on lines -76 to +90

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems out of the scope of this PR.

)

@property
def is_recently_created(self):
return (datetime.utcnow() - self.created_at).total_seconds() < 240
return (datetime.now(timezone.utc) - self.created_at) < timedelta(minutes=4)

def has_evaluation(self, session: Session) -> bool:
if self.status == DiffStatus.IGNORED:
Expand Down
6 changes: 3 additions & 3 deletions scripts/bug_retriever.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import argparse
from datetime import datetime
from datetime import datetime, timezone
from logging import getLogger

import dateutil.parser
Expand Down Expand Up @@ -61,7 +61,7 @@ def retrieve_bugs(self, limit: int | None = None) -> None:
changed_ids |= deleted_component_ids

# Get IDs of bugs between (two years and six months ago) and now.
two_years_and_six_months_ago = datetime.utcnow() - relativedelta(
two_years_and_six_months_ago = datetime.now(timezone.utc) - relativedelta(
years=2, months=6
)
logger.info("Retrieving bug IDs since %s", two_years_and_six_months_ago)
Expand Down Expand Up @@ -121,7 +121,7 @@ def retrieve_bugs(self, limit: int | None = None) -> None:
test_failure_bug_ids = [
item["bug_id"]
for item in test_scheduling.get_failure_bugs(
two_years_and_six_months_ago, datetime.utcnow()
two_years_and_six_months_ago, datetime.now(timezone.utc)
)
if item["bug_id"] is not None
]
Expand Down
4 changes: 2 additions & 2 deletions scripts/commit_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pickle
import re
import subprocess
from datetime import datetime
from datetime import datetime, timezone
from logging import INFO, basicConfig, getLogger
from typing import cast

Expand Down Expand Up @@ -719,7 +719,7 @@ def classify_methods(self, commit):
# Get commit hash from 4 months before the analysis time.
# The method-level analyzer needs 4 months of history.
stop_hash = None
four_months_ago = datetime.utcnow() - relativedelta(months=4)
four_months_ago = datetime.now(timezone.utc) - relativedelta(months=4)
for commit in repository.get_commits():
if dateutil.parser.parse(commit["pushdate"]) >= four_months_ago:
stop_hash = tuple(
Expand Down
Loading