Skip to content
Merged
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
31 changes: 1 addition & 30 deletions augur/application/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Any, Optional
import os
from augur.application.db.models import Config
from augur.application.db.util import execute_session_query
from augur.application.db.util import execute_session_query, convert_type_of_value

def get_development_flag_from_config():

Expand Down Expand Up @@ -109,35 +109,6 @@ def get_development_flag():
}


def convert_type_of_value(config_dict, logger=None):

data_type = config_dict["type"]

if data_type == "str" or data_type is None:
return config_dict

elif data_type == "int":
config_dict["value"] = int(config_dict["value"])

elif data_type == "bool":
value = config_dict["value"]

if value.lower() == "false":
config_dict["value"] = False
else:
config_dict["value"] = True

elif data_type == "float":
config_dict["value"] = float(config_dict["value"])

else:
if logger:
logger.error(f"Need to add support for {data_type} types to config")
else:
print(f"Need to add support for {data_type} types to config")

return config_dict

class AugurConfig():

from augur.application.db.session import DatabaseSession
Expand Down
68 changes: 30 additions & 38 deletions augur/application/db/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import sqlalchemy as s
from sqlalchemy import func
from sqlalchemy.exc import DataError

Check warning on line 7 in augur/application/db/lib.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0611: Unused DataError imported from sqlalchemy.exc (unused-import) Raw Output: augur/application/db/lib.py:7:0: W0611: Unused DataError imported from sqlalchemy.exc (unused-import)
from sqlalchemy.dialects import postgresql
from sqlalchemy.exc import OperationalError
from psycopg2.errors import DeadlockDetected
Expand All @@ -13,41 +13,11 @@
from augur.application.db.models import Config, Repo, Commit, WorkerOauth, Issue, PullRequest, PullRequestReview, ContributorsAlias,UnresolvedCommitEmail, Contributor, CollectionStatus, UserGroup, RepoGroup
from augur.tasks.util.collection_state import CollectionState
from augur.application.db import get_session, get_engine
from augur.application.db.util import execute_session_query
from augur.application.db.util import execute_session_query, convert_type_of_value
from augur.application.db.session import remove_duplicates_by_uniques, remove_null_characters_from_list_of_dicts

logger = logging.getLogger("db_lib")

def convert_type_of_value(config_dict, logger=None):


data_type = config_dict["type"]

if data_type == "str" or data_type is None:
return config_dict

if data_type == "int":
config_dict["value"] = int(config_dict["value"])

elif data_type == "bool":
value = config_dict["value"]

if value.lower() == "false":
config_dict["value"] = False
else:
config_dict["value"] = True

elif data_type == "float":
config_dict["value"] = float(config_dict["value"])

else:
if logger:
logger.error(f"Need to add support for {data_type} types to config")
else:
print(f"Need to add support for {data_type} types to config")

return config_dict


def get_section(section_name) -> dict:
"""Get a section of data from the config.
Expand Down Expand Up @@ -197,7 +167,7 @@

try:
working_commits = fetchall_data_from_sql_text(query)
except:

Check warning on line 170 in augur/application/db/lib.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0702: No exception type(s) specified (bare-except) Raw Output: augur/application/db/lib.py:170:4: W0702: No exception type(s) specified (bare-except)
working_commits = []

return working_commits
Expand All @@ -213,7 +183,7 @@

try:
missing_commit_hashes = fetchall_data_from_sql_text(fetch_missing_hashes_sql)
except:

Check warning on line 186 in augur/application/db/lib.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0702: No exception type(s) specified (bare-except) Raw Output: augur/application/db/lib.py:186:4: W0702: No exception type(s) specified (bare-except)
missing_commit_hashes = []

return missing_commit_hashes
Expand All @@ -233,7 +203,7 @@
return session.query(CollectionStatus).filter(getattr(CollectionStatus,f"{collection_type}_status" ) == CollectionState.COLLECTING.value).count()


def facade_bulk_insert_commits(logger, records):

Check warning on line 206 in augur/application/db/lib.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0621: Redefining name 'logger' from outer scope (line 19) (redefined-outer-name) Raw Output: augur/application/db/lib.py:206:31: W0621: Redefining name 'logger' from outer scope (line 19) (redefined-outer-name)

with get_session() as session:

Expand All @@ -255,24 +225,46 @@

facade_bulk_insert_commits(logger, firsthalfRecords)
facade_bulk_insert_commits(logger, secondhalfRecords)
elif len(records) == 1 and isinstance(e,DataError) and "time zone displacement" in f"{e}":
elif len(records) == 1:
commit_record = records[0]
#replace incomprehensible dates with epoch.
#2021-10-11 11:57:46 -0500

# placeholder_date = "1970-01-01 00:00:15 -0500"
placeholder_date = commit_record['author_timestamp']
placeholder_date = commit_record['cmt_author_timestamp']

postgres_valid_timezones = {
-1200, -1100, -1000, -930, -900, -800, -700,
-600, -500, -400, -300, -230, -200, -100, 000,
100, 200, 300, 330, 400, 430, 500, 530, 545, 600,
630, 700, 800, 845, 900, 930, 1000, 1030, 1100, 1200,
1245, 1300, 1400
}

# Reconstruct timezone portion of the date string to UTC
placeholder_date = re.split("[-+]", placeholder_date)
placeholder_date.pop()
placeholder_date = "-".join(placeholder_date) + "+0000"
placeholder_date_segments = re.split(" ", placeholder_date)
tzdata = placeholder_date_segments.pop()

if ":" in tzdata:
tzdata = tzdata.replace(":", "")

if int(tzdata) not in postgres_valid_timezones:
tzdata = "+0000"
else:
raise e

placeholder_date_segments.append(tzdata)

placeholder_date = " ".join(placeholder_date_segments)

#Check for improper utc timezone offset
#UTC timezone offset should be between -14:00 and +14:00

commit_record['author_timestamp'] = placeholder_date
commit_record['committer_timestamp'] = placeholder_date
# analyzecommit.generate_commit_record() defines the keys on the commit_record dictionary
commit_record['cmt_author_timestamp'] = placeholder_date
commit_record['cmt_committer_timestamp'] = placeholder_date

logger.warning(f"commit with invalid timezone set to UTC: {commit_record['cmt_commit_hash']}")

session.execute(
s.insert(Commit),
Expand All @@ -283,7 +275,7 @@
raise e


def batch_insert_contributors(logger, data: Union[List[dict], dict]) -> Optional[List[dict]]:

Check warning on line 278 in augur/application/db/lib.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0621: Redefining name 'logger' from outer scope (line 19) (redefined-outer-name) Raw Output: augur/application/db/lib.py:278:30: W0621: Redefining name 'logger' from outer scope (line 19) (redefined-outer-name)

batch_size = 1000

Expand All @@ -294,7 +286,7 @@



def bulk_insert_dicts(logger, data: Union[List[dict], dict], table, natural_keys: List[str], return_columns: Optional[List[str]] = None, string_fields: Optional[List[str]] = None, on_conflict_update:bool = True) -> Optional[List[dict]]:

Check warning on line 289 in augur/application/db/lib.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0621: Redefining name 'logger' from outer scope (line 19) (redefined-outer-name) Raw Output: augur/application/db/lib.py:289:22: W0621: Redefining name 'logger' from outer scope (line 19) (redefined-outer-name)

if isinstance(data, list) is False:

Expand Down
30 changes: 30 additions & 0 deletions augur/application/db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,40 @@
row_dict = row.__dict__
try:
del row_dict['_sa_instance_state']
except:

Check warning on line 54 in augur/application/db/util.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0702: No exception type(s) specified (bare-except) Raw Output: augur/application/db/util.py:54:8: W0702: No exception type(s) specified (bare-except)
pass

new_list.append(row_dict)

return new_list



def convert_type_of_value(config_dict, logger=None):

data_type = config_dict["type"]

if data_type == "str" or data_type is None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)

return config_dict

elif data_type == "int":
config_dict["value"] = int(config_dict["value"])

elif data_type == "bool":
value = config_dict["value"]

if value.lower() == "false":
config_dict["value"] = False
else:
config_dict["value"] = True

elif data_type == "float":
config_dict["value"] = float(config_dict["value"])

else:
if logger:
logger.error(f"Need to add support for {data_type} types to config")
else:
print(f"Need to add support for {data_type} types to config")

return config_dict
2 changes: 1 addition & 1 deletion augur/application/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def get_all_repos_count(**kwargs):

result = controller.get_repo_count(source="all", **kwargs)

return result
return result
Loading