Skip to content

Commit

Permalink
RAS-1378 Fix datetime deprecation warning on party service (#448)
Browse files Browse the repository at this point in the history
* updating datetime.utcnnow to datetime.now(utc)

* auto patch increment

* making sqlalchemy get the time rather than datetime

* adding CODEOWNERS and removing tz info from created on columns

---------

Co-authored-by: ras-rm-pr-bot <rasrm.team@ons.gov.uk>
  • Loading branch information
arroyoAle and ras-rm-pr-bot authored Dec 13, 2024
1 parent 4b8178d commit af73b37
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @ONSdigital/sdc-rmras
4 changes: 2 additions & 2 deletions _infra/helm/party/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 2.5.12
version: 2.5.13

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 2.5.12
appVersion: 2.5.13
6 changes: 3 additions & 3 deletions ras_party/controllers/pending_survey_controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import uuid
from datetime import datetime, timedelta
from datetime import UTC, datetime, timedelta
from urllib.error import HTTPError

import structlog
Expand Down Expand Up @@ -129,7 +129,7 @@ def delete_pending_surveys(session):
Deletes all the existing pending surveys which have expired
:param session A db session
"""
_expired_hrs = datetime.utcnow() - timedelta(seconds=float(current_app.config["EMAIL_TOKEN_EXPIRY"]))
_expired_hrs = datetime.now(UTC) - timedelta(seconds=float(current_app.config["EMAIL_TOKEN_EXPIRY"]))
pending_shares = session.query(PendingSurveys).filter(PendingSurveys.time_shared < _expired_hrs)
pending_shares.delete()
logger.info("Deletion complete")
Expand All @@ -143,7 +143,7 @@ def get_unique_pending_surveys(is_transfer, session):
:type is_transfer: bool
:param session A db session
"""
_expired_hrs = datetime.utcnow() - timedelta(seconds=float(current_app.config["EMAIL_TOKEN_EXPIRY"]))
_expired_hrs = datetime.now(UTC) - timedelta(seconds=float(current_app.config["EMAIL_TOKEN_EXPIRY"]))
pending_shares_ready_for_deletion = (
session.query(PendingSurveys)
.filter(PendingSurveys.time_shared < _expired_hrs)
Expand Down
18 changes: 9 additions & 9 deletions ras_party/models/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import enum
import logging
import uuid
Expand All @@ -18,6 +17,7 @@
)
from sqlalchemy.dialects.postgresql import JSONB, UUID
from sqlalchemy.orm import declarative_base, relationship
from sqlalchemy.sql import func
from sqlalchemy.types import Enum
from werkzeug.exceptions import BadRequest

Expand All @@ -39,7 +39,7 @@ class Business(Base):
attributes = relationship(
"BusinessAttributes", backref="business", order_by="desc(BusinessAttributes.created_on)", lazy="joined"
)
created_on = Column(DateTime, default=datetime.datetime.utcnow)
created_on = Column(DateTime, default=func.now())

@staticmethod
def validate(json_packet, schema):
Expand Down Expand Up @@ -188,7 +188,7 @@ class BusinessAttributes(Base):
sample_summary_id = Column(Text)
collection_exercise = Column(Text)
attributes = Column(JSONB)
created_on = Column(DateTime, default=datetime.datetime.utcnow)
created_on = Column(DateTime, default=func.now())
name = Column(Text) # New columns placed at end of list in case code uses positional rather than named references
trading_as = Column(Text)
Index("attributes_name_idx", name)
Expand Down Expand Up @@ -232,9 +232,9 @@ class BusinessRespondent(Base):
business_id = Column(UUID, ForeignKey("business.party_uuid"), primary_key=True)
respondent_id = Column(Integer, ForeignKey("respondent.id"), primary_key=True)
status = Column("status", Enum(BusinessRespondentStatus), default=BusinessRespondentStatus.ACTIVE)
effective_from = Column(DateTime, default=datetime.datetime.utcnow)
effective_from = Column(DateTime, default=func.now())
effective_to = Column(DateTime)
created_on = Column(DateTime, default=datetime.datetime.utcnow)
created_on = Column(DateTime, default=func.now())

business = relationship("Business", back_populates="respondents", lazy="joined")
respondent = relationship("Respondent", back_populates="businesses", lazy="joined")
Expand All @@ -257,7 +257,7 @@ class PendingEnrolment(Base):
business_id = Column(UUID)
survey_id = Column(UUID)

created_on = Column(DateTime, default=datetime.datetime.utcnow)
created_on = Column(DateTime, default=func.now())
respondent = relationship("Respondent")
Index("pending_enrolment_case_idx", case_id)

Expand All @@ -279,7 +279,7 @@ class Respondent(Base):
last_name = Column(Text)
telephone = Column(Text)
mark_for_deletion = Column(Boolean, default=False)
created_on = Column(DateTime, default=datetime.datetime.utcnow)
created_on = Column(DateTime, default=func.now())
password_verification_token = Column(Text)
password_reset_counter = Column(Integer, default=0)
pending_enrolment = relationship("PendingEnrolment", back_populates="respondent")
Expand Down Expand Up @@ -360,7 +360,7 @@ class Enrolment(Base):
respondent_id = Column(Integer, primary_key=True)
survey_id = Column(Text, primary_key=True)
status = Column("status", Enum(EnrolmentStatus), default=EnrolmentStatus.PENDING)
created_on = Column(DateTime, default=datetime.datetime.utcnow)
created_on = Column(DateTime, default=func.now())

business_respondent = relationship("BusinessRespondent", back_populates="enrolment", lazy="joined")
Index("enrolment_business_idx", business_id)
Expand All @@ -387,7 +387,7 @@ class PendingSurveys(Base):
email_address = Column(Text, primary_key=True)
business_id = Column(UUID, primary_key=True)
survey_id = Column(Text, primary_key=True)
time_shared = Column(DateTime, default=datetime.datetime.utcnow)
time_shared = Column(DateTime, default=func.now())
shared_by = Column(UUID)
batch_no = Column(UUID, default=uuid.uuid4)
is_transfer = Column(Boolean, default=False)
Expand Down

0 comments on commit af73b37

Please sign in to comment.