Function _run_metadata_migration
has a Cognitive Complexity of 29 (exceeds 10 allowed). Consider refactoring.
def _run_metadata_migration(
metadata_migration: Callable[[dict], MigrationResult],
use_upload_jobs_table: bool,
gcs_tasks: RollbackableQueue,
session: Session,
DownloadableFiles
has 22 functions (exceeds 20 allowed). Consider refactoring.
class DownloadableFiles(CommonColumns):
"""
Store required fields from:
https://github.com/CIMAC-CIDC/cidc-schemas/blob/master/cidc_schemas/schemas/artifacts/artifact_core.json
"""
Function _change_download_permissions
has a Cognitive Complexity of 19 (exceeds 10 allowed). Consider refactoring.
def _change_download_permissions(
trial_id: str, upload_type: str, grant: bool, session: Session
) -> None:
"""
Allows for widespread granting/revoking of existing download permissions in GCS ACL
Function _remove_optional_uuid_recursive
has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
def _remove_optional_uuid_recursive(target: dict, uuid: str):
"""
If target contains an item : dict with {"upload_placeholder":uuid}, removes that item and returns the modified target
If no such item is found, continues recursively as depth first search
If the uuid is never found, returns the target unchanged
Function inner
has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
def inner(f):
@wraps(f)
def wrapped(*args, **kwargs):
logger.info(f"upload_handler({f.__name__}) started")
template, xlsx_file = extract_schema_and_xlsx(allowed_types)
Function unmarshal_request
has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
def unmarshal_request(schema: BaseSchema, kwarg_name: str, load_sqla: bool = True):
"""
Generate a decorator that will load and validate the JSON body of
the current request object as an instance of `schema` and pass
the loaded instance to the decorated function as a keyword argument
Function insert
has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
def insert(
self,
session: Session,
commit: bool = True,
) -> None:
Function create
has 8 arguments (exceeds 6 allowed). Consider refactoring.
def create(
Function create_from_blob
has 7 arguments (exceeds 6 allowed). Consider refactoring.
def create_from_blob(
Function is_valid_transition
has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
def is_valid_transition(
cls, current: str, target: str, is_manifest: bool = False
) -> bool:
"""
Enforce logic about which state transitions are valid. E.g.,
Avoid too many return
statements within this function.
return True
Function build_file_filter
has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
def build_file_filter(
trial_ids: List[str] = [], facets: List[List[str]] = [], user: Users = None
) -> Callable[[Query], Query]:
"""
Build a file filter function based on the provided parameters. The resultant
Function _encode_and_publish
has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
def _encode_and_publish(content: str, topic: str) -> Future:
"""Convert `content` to bytes and publish it to `topic`."""
pubsub_publisher = pubsub.PublisherClient()
topic = pubsub_publisher.topic_path(GOOGLE_CLOUD_PROJECT, topic)
data = bytes(content, "utf-8")
Function authorize
has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
def authorize(
user: Users, allowed_roles: List[str], resource: str, method: str
) -> bool:
"""Check if the current user is authorized to act on the current request's resource.
Raises Unauthorized