Browse Source

ref: replace trivial uses of utcnow with tz-aware now (#65085)

utcnow is a warning in 3.12 and removed in 3.14

<!-- Describe your PR here. -->
anthony sottile 1 year ago
parent
commit
7dba2dc562

+ 1 - 1
src/sentry/api/base.py

@@ -569,7 +569,7 @@ class StatsMixin:
             if end_s:
                 end = to_datetime(float(end_s))
             else:
-                end = datetime.utcnow().replace(tzinfo=timezone.utc)
+                end = datetime.now(timezone.utc)
         except ValueError:
             raise ParseError(detail="until must be a numeric timestamp.")
 

+ 1 - 1
src/sentry/api/endpoints/organization_details.py

@@ -333,7 +333,7 @@ class OrganizationSerializer(BaseOrganizationSerializer):
         return attrs
 
     def save_trusted_relays(self, incoming, changed_data, organization):
-        timestamp_now = datetime.utcnow().replace(tzinfo=timezone.utc).isoformat()
+        timestamp_now = datetime.now(timezone.utc).isoformat()
         option_key = "sentry:trusted-relays"
         try:
             # get what we already have

+ 1 - 1
src/sentry/api/endpoints/organization_transaction_anomaly_detection.py

@@ -66,7 +66,7 @@ def get_time_params(start: datetime, end: datetime) -> MappedParams:
         granularity = 600
 
     additional_time_needed = snuba_range - anomaly_detection_range
-    now = datetime.utcnow().astimezone(timezone.utc)
+    now = datetime.now(timezone.utc)
     start_limit = now - timedelta(days=90)
     end_limit = now
     start = max(start, start_limit)

+ 3 - 3
src/sentry/dynamic_sampling/rules/helpers/latest_releases.py

@@ -86,7 +86,7 @@ class BoostedReleases:
         # We get release models in order to have all the information to extend the releases we get from the cache.
         models = self._get_releases_models()
 
-        current_timestamp = datetime.utcnow().replace(tzinfo=timezone.utc).timestamp()
+        current_timestamp = datetime.now(timezone.utc).timestamp()
 
         extended_boosted_releases = []
         expired_boosted_releases = []
@@ -154,7 +154,7 @@ class ProjectBoostedReleases:
         self.redis_client.hset(
             cache_key,
             self._generate_cache_key_for_boosted_release(release_id, environment),
-            datetime.utcnow().replace(tzinfo=timezone.utc).timestamp(),
+            datetime.now(timezone.utc).timestamp(),
         )
         # In order to avoid having the boosted releases hash in memory for an indefinite amount of time, we will expire
         # it after a specific timeout.
@@ -209,7 +209,7 @@ class ProjectBoostedReleases:
         """
         cache_key = self._generate_cache_key_for_boosted_releases_hash()
         boosted_releases = self.redis_client.hgetall(cache_key)
-        current_timestamp = datetime.utcnow().replace(tzinfo=timezone.utc).timestamp()
+        current_timestamp = datetime.now(timezone.utc).timestamp()
 
         LRBRelease = namedtuple("LRBRelease", ["key", "timestamp"])
         lrb_release = None

+ 2 - 2
src/sentry/event_manager.py

@@ -1146,7 +1146,7 @@ def _tsdb_record_all_metrics(jobs: Sequence[Job]) -> None:
 
 @metrics.wraps("save_event.nodestore_save_many")
 def _nodestore_save_many(jobs: Sequence[Job], app_feature: str) -> None:
-    inserted_time = datetime.utcnow().replace(tzinfo=timezone.utc).timestamp()
+    inserted_time = datetime.now(timezone.utc).timestamp()
     for job in jobs:
         # Write the event to Nodestore
         subkeys = {}
@@ -2370,7 +2370,7 @@ def save_attachment(
     if start_time is not None:
         timestamp = to_datetime(start_time)
     else:
-        timestamp = datetime.utcnow().replace(tzinfo=timezone.utc)
+        timestamp = datetime.now(timezone.utc)
 
     try:
         attachment.data

+ 1 - 1
src/sentry/incidents/logic.py

@@ -382,7 +382,7 @@ def calculate_incident_time_range(incident, start=None, end=None, windowed_stats
     retention = quotas.get_event_retention(organization=incident.organization) or 90
     start = max(
         start.replace(tzinfo=timezone.utc),
-        datetime.utcnow().replace(tzinfo=timezone.utc) - timedelta(days=retention),
+        datetime.now(timezone.utc) - timedelta(days=retention),
     )
     end = max(start, end.replace(tzinfo=timezone.utc))
 

+ 1 - 1
src/sentry/incidents/receivers.py

@@ -23,4 +23,4 @@ def add_project_to_include_all_rules(instance, created, **kwargs):
 
 @receiver(pre_save, sender=IncidentTrigger)
 def pre_save_incident_trigger(instance, sender, *args, **kwargs):
-    instance.date_modified = datetime.utcnow().replace(tzinfo=timezone.utc)
+    instance.date_modified = datetime.now(timezone.utc)

+ 1 - 1
src/sentry/monitors/logic/mark_failed.py

@@ -263,7 +263,7 @@ def create_issue_platform_occurrence(
     from sentry.issues.producer import PayloadType, produce_occurrence_to_kafka
 
     monitor_env = failed_checkin.monitor_environment
-    current_timestamp = datetime.utcnow().replace(tzinfo=timezone.utc)
+    current_timestamp = datetime.now(timezone.utc)
 
     occurrence_data = get_occurrence_data(failed_checkin)
 

+ 1 - 1
src/sentry/profiles/task.py

@@ -910,7 +910,7 @@ def _track_outcome(
         key_id=None,
         outcome=outcome,
         reason=reason,
-        timestamp=datetime.utcnow().replace(tzinfo=timezone.utc),
+        timestamp=datetime.now(timezone.utc),
         event_id=event_id,
         category=DataCategory.PROFILE_INDEXED,
         quantity=1,

+ 1 - 1
src/sentry/projectoptions/manager.py

@@ -76,7 +76,7 @@ class ProjectOptionsManager:
         ProjectOption.objects.set_value(
             project,
             "sentry:relay-rev-lastchange",
-            json.datetime_to_str(datetime.utcnow().replace(tzinfo=timezone.utc)),
+            json.datetime_to_str(datetime.now(timezone.utc)),
         )
 
     def register(self, key, default=None, epoch_defaults=None):

Some files were not shown because too many files changed in this diff