scitran/core

View on GitHub
api/dao/hierarchy.py

Summary

Maintainability
F
5 days
Test Coverage

Function is_session_compliant has a Cognitive Complexity of 96 (exceeds 5 allowed). Consider refactoring.
Open

def is_session_compliant(session, template):
    """
    Given a project-level session template and a session,
    returns True/False if the session is in compliance with the template
    """
Severity: Minor
Found in api/dao/hierarchy.py - About 1 day to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File hierarchy.py has 475 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import bson
import copy
import datetime
import dateutil.parser
import difflib
Severity: Minor
Found in api/dao/hierarchy.py - About 7 hrs to fix

    Function get_parent_tree has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_parent_tree(cont_name, _id):
        """
        Given a contanier and an id, returns that container and its parent tree.
    
        For example, given `sessions`, `<session_id>`, it will return:
    Severity: Minor
    Found in api/dao/hierarchy.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _upsert_container has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def _upsert_container(cont, cont_type, parent, parent_type, upload_type, timestamp):
        cont['modified'] = timestamp
    
        if cont.get('timestamp'):
            cont['timestamp'] = dateutil.parser.parse(cont['timestamp'])
    Severity: Minor
    Found in api/dao/hierarchy.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _update_hierarchy has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def _update_hierarchy(container, container_type, metadata):
        project_id = container.get('project') # for sessions
        now = datetime.datetime.utcnow()
    
        if container_type == 'acquisition':
    Severity: Minor
    Found in api/dao/hierarchy.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function upsert_fileinfo has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def upsert_fileinfo(cont_name, _id, fileinfo):
    
        cont_name = containerutil.pluralize(cont_name)
        _id = bson.ObjectId(_id)
    
    
    Severity: Minor
    Found in api/dao/hierarchy.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _upsert_container has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _upsert_container(cont, cont_type, parent, parent_type, upload_type, timestamp):
    Severity: Minor
    Found in api/dao/hierarchy.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if 'deleted' in f or not check_cont(f, fr_temp):
                                  # Didn't find a match, on to the next one
                                  continue
                              else:
                                  count += 1
      Severity: Major
      Found in api/dao/hierarchy.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if count >= min_count:
                                break
                    if count < min_count:
        Severity: Major
        Found in api/dao/hierarchy.py - About 45 mins to fix

          Function _find_or_create_destination_project has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def _find_or_create_destination_project(group_id, project_label, timestamp, user):
              group_id, project_label = _group_id_fuzzy_match(group_id, project_label)
              group = config.db.groups.find_one({'_id': group_id})
          
              if project_label == '':
          Severity: Minor
          Found in api/dao/hierarchy.py - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function _get_targets has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def _get_targets(project_obj, session, acquisition, type_, timestamp):
          Severity: Minor
          Found in api/dao/hierarchy.py - About 35 mins to fix

            Function _create_query has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def _create_query(cont, cont_type, parent_type, parent_id, upload_type):
            Severity: Minor
            Found in api/dao/hierarchy.py - About 35 mins to fix

              Avoid too many return statements within this function.
              Open

                      return True
              Severity: Major
              Found in api/dao/hierarchy.py - About 30 mins to fix

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                    if fileinfo.get('size') is not None:
                        if type(fileinfo['size']) != int:
                            log.warn('Fileinfo passed with non-integer size')
                            fileinfo['size'] = int(fileinfo['size'])
                Severity: Major
                Found in api/dao/hierarchy.py and 1 other location - About 3 hrs to fix
                api/dao/hierarchy.py on lines 274..277

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 66.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                    if fileinfo.get('size') is not None:
                        if type(fileinfo['size']) != int:
                            log.warn('Fileinfo passed with non-integer size')
                            fileinfo['size'] = int(fileinfo['size'])
                Severity: Major
                Found in api/dao/hierarchy.py and 1 other location - About 3 hrs to fix
                api/dao/hierarchy.py on lines 257..260

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 66.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                        project_obj = config.db.projects.find_one({'_id': session_obj['project'], 'deleted': {'$exists': False}}, projection=PROJECTION_FIELDS + ['name'])
                Severity: Major
                Found in api/dao/hierarchy.py and 1 other location - About 1 hr to fix
                api/dao/hierarchy.py on lines 440..440

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 43.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                    project_obj = config.db.projects.find_one({'_id': session_obj['project'], 'deleted': {'$exists': False}}, projection=PROJECTION_FIELDS + ['name'])
                Severity: Major
                Found in api/dao/hierarchy.py and 1 other location - About 1 hr to fix
                api/dao/hierarchy.py on lines 472..472

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 43.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                        for k,v in fileinfo.iteritems():
                            update_set[self.file_prefix + '.$.' + k] = v
                Severity: Major
                Found in api/dao/hierarchy.py and 2 other locations - About 1 hr to fix
                api/dao/liststorage.py on lines 87..88
                api/dao/liststorage.py on lines 133..134

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 38.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 9 locations. Consider refactoring.
                Open

                    if c_metadata.get('timestamp'):
                        c_metadata['timestamp'] = dateutil.parser.parse(c_metadata['timestamp'])
                Severity: Major
                Found in api/dao/hierarchy.py and 8 other locations - About 45 mins to fix
                api/dao/hierarchy.py on lines 531..532
                api/handlers/containerhandler.py on lines 436..437
                api/handlers/containerhandler.py on lines 484..485
                api/handlers/listhandler.py on lines 282..283
                api/handlers/listhandler.py on lines 298..299
                bin/oneoffs/load_external_data.py on lines 32..33
                bin/oneoffs/load_external_data.py on lines 34..35
                bin/oneoffs/load_external_data.py on lines 36..37

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 35.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 9 locations. Consider refactoring.
                Open

                            if session.get('timestamp'):
                                session['timestamp'] = dateutil.parser.parse(session['timestamp'])
                Severity: Major
                Found in api/dao/hierarchy.py and 8 other locations - About 45 mins to fix
                api/dao/hierarchy.py on lines 512..513
                api/handlers/containerhandler.py on lines 436..437
                api/handlers/containerhandler.py on lines 484..485
                api/handlers/listhandler.py on lines 282..283
                api/handlers/listhandler.py on lines 298..299
                bin/oneoffs/load_external_data.py on lines 32..33
                bin/oneoffs/load_external_data.py on lines 34..35
                bin/oneoffs/load_external_data.py on lines 36..37

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 35.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                        if user and not has_access(user, session_obj, 'rw'):
                            raise APIPermissionException('User {} does not have read-write access to session {}'.format(user, session_uid))
                Severity: Minor
                Found in api/dao/hierarchy.py and 2 other locations - About 35 mins to fix
                api/dao/hierarchy.py on lines 316..317
                api/dao/hierarchy.py on lines 431..432

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 33.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                    if user and not has_access(user, session_obj, 'rw'):
                        raise APIPermissionException('User {} does not have read-write access to session {}'.format(user, session_uid))
                Severity: Minor
                Found in api/dao/hierarchy.py and 2 other locations - About 35 mins to fix
                api/dao/hierarchy.py on lines 316..317
                api/dao/hierarchy.py on lines 467..468

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 33.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                        if user and not has_access(user, group, 'rw'):
                            raise APIPermissionException('User {} does not have read-write access to group {}'.format(user, group_id))
                Severity: Minor
                Found in api/dao/hierarchy.py and 2 other locations - About 35 mins to fix
                api/dao/hierarchy.py on lines 431..432
                api/dao/hierarchy.py on lines 467..468

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 33.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status