Skip to content

Commit

Permalink
Two small bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chouinar committed May 2, 2024
1 parent 66ba784 commit 8ee7388
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def process_opportunity(

logger.info("Transforming and upserting opportunity", extra=extra)
transformed_opportunity = transform_opportunity(source_opportunity, target_opportunity)
self.db_session.add(transformed_opportunity)
self.db_session.merge(transformed_opportunity)

if is_insert:
self.increment(self.Metrics.TOTAL_RECORDS_INSERTED)
Expand Down Expand Up @@ -139,13 +139,16 @@ def process_one_to_many_lookup_tables(self) -> None:


def transform_opportunity(
source_opportunity: Topportunity, target_opportunity: Opportunity | None
source_opportunity: Topportunity, existing_opportunity: Opportunity | None
) -> Opportunity:
log_extra = {"opportunity_id": source_opportunity.opportunity_id}

if target_opportunity is None:
if existing_opportunity is None:
logger.info("Creating new opportunity record", extra=log_extra)
target_opportunity = Opportunity(opportunity_id=source_opportunity.opportunity_id)

# We always create a new opportunity record here and merge it in the calling function
# this way if there is any error doing the transformation, we don't modify the existing one.
target_opportunity = Opportunity(opportunity_id=source_opportunity.opportunity_id)

target_opportunity.opportunity_number = source_opportunity.oppnumber
target_opportunity.opportunity_title = source_opportunity.opptitle
Expand Down
3 changes: 3 additions & 0 deletions api/src/util/datetime_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def adjust_timezone(timestamp: datetime, timezone_str: str) -> datetime:


def make_timezone_aware(timestamp: datetime, timezone_str: str) -> datetime:
# First make certain the tzinfo is truly None otherwise pytz will error
# if it actually had a tzinfo this means we're effectively ignoring anything about it.
timestamp.replace(tzinfo=None)
new_timezone = pytz.timezone(timezone_str)
return new_timezone.localize(timestamp)

Expand Down

0 comments on commit 8ee7388

Please sign in to comment.