scitran/core

View on GitHub

Showing 518 of 518 total issues

Avoid deeply nested control flow statements.
Open

                    if file_:
                        file_['input'] = True
                        files.append(file_)

Severity: Major
Found in bin/database.py - About 45 mins to fix

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

        def set_origin(self, drone_request, job_context):
            """
            Add an origin to the request object. Used later in request handler logic.
    
            Pretty clear duplication of logic with superuser_request / drone_request;
    Severity: Minor
    Found in api/web/base.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

    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

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

                  filename = arc_prefix + '_ '+datetime.datetime.utcnow().strftime('%Y%m%d_%H%M%S') + '.tar'
      Severity: Minor
      Found in api/download.py and 1 other location - About 45 mins to fix
      api/download.py on lines 228..229

      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 2 locations. Consider refactoring.
      Open

          pipeline = [
              {'$match': match_q},
              {'$group': {'_id': '$subject._id'}},
              {'$group': {'_id': 1, 'count': { '$sum': 1 }}}
      Severity: Minor
      Found in api/dao/containerutil.py and 1 other location - About 45 mins to fix
      api/handlers/reporthandler.py on lines 391..394

      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 2 locations. Consider refactoring.
      Open

              session = config.db.sessions.find_one_and_update(
                  query, {
                      '$set': updates,
                      '$setOnInsert': insert_map
                  },
      Severity: Minor
      Found in api/placer.py and 1 other location - About 45 mins to fix
      api/placer.py on lines 666..672

      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

      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

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

                if payload.get('timestamp'):
                    payload['timestamp'] = dateutil.parser.parse(payload['timestamp'])
        Severity: Major
        Found in api/handlers/containerhandler.py and 8 other locations - About 45 mins to fix
        api/dao/hierarchy.py on lines 512..513
        api/dao/hierarchy.py on lines 531..532
        api/handlers/containerhandler.py on lines 436..437
        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 2 locations. Consider refactoring.
        Open

                    if has_access:
                        return exec_op(method, _id=_id, payload=payload)
                    else:
                        handler.abort(403, 'user not authorized to perform a {} operation on the container'.format(method))
        Severity: Minor
        Found in api/auth/containerauth.py and 1 other location - About 45 mins to fix
        api/auth/containerauth.py on lines 106..109

        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

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

        def dispatcher(router, request, response):
            try:
                if uwsgi is not None:
                    uwsgi.set_logvar('request_id', request.id)
            except: # pylint: disable=bare-except
        Severity: Minor
        Found in api/web/start.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_parent_tree has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_parent_tree(self, _id, cont=None, projection=None, add_self=False):
                parents = []
        
                curr_storage = self
        
        
        Severity: Minor
        Found in api/dao/basecontainerstorage.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 _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

        Avoid deeply nested control flow statements.
        Open

                        for a in acquisitions:
                            a.pop('info', None)
                            files = a.pop('files', [])
                            remove_blacklisted_keys(a)
        
        
        Severity: Major
        Found in bin/dicom_doctype.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if code is None:
                                      code = 'unknown_subject'
                                      subject['code'] = code
                                  subject_dict[code] = subject
          Severity: Major
          Found in api/download.py - About 45 mins to fix

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

                def update_el(self, _id, payload, unset_payload=None, recursive=False, r_payload=None, replace_metadata=False):
                    result = super(ProjectStorage, self).update_el(_id, payload, unset_payload=unset_payload, recursive=recursive, r_payload=r_payload, replace_metadata=replace_metadata)
            
                    if result.modified_count < 1:
                        raise APINotFoundException('Could not find project {}'.format(_id))
            Severity: Minor
            Found in api/dao/containerstorage.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

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

                        if has_access:
                            return exec_op(method, _id=_id, payload=payload)
                        else:
                            handler.abort(403, 'user not authorized to perform a {} operation on parent container'.format(method))
            Severity: Minor
            Found in api/auth/containerauth.py and 1 other location - About 45 mins to fix
            api/auth/containerauth.py on lines 85..88

            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

            Consider simplifying this complex logical expression.
            Open

                        if access >= INTEGER_PERMISSIONS['admin']:
                            pass
                        elif method == 'POST' and access >= INTEGER_PERMISSIONS['rw'] and payload['user'] == handler.uid:
                            pass
                        elif method == 'GET' and (access >= INTEGER_PERMISSIONS['ro'] or container.get('public')):
            Severity: Major
            Found in api/auth/listauth.py - About 40 mins to fix

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

                          acquisitions = config.db.acquisitions.find({'session': {'$in': session_ids}, 'deleted': {'$exists': False}}, {'_id': 1})
              Severity: Minor
              Found in api/handlers/reporthandler.py and 1 other location - About 40 mins to fix
              api/download.py on lines 356..356

              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 34.

              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 4 locations. Consider refactoring.
              Open

                      config.db.users.update_one({'_id': uid, 'avatar': {'$exists': False}}, {'$set':{'avatar': provider_avatar, 'modified': timestamp}})
              Severity: Major
              Found in api/auth/authproviders.py and 3 other locations - About 40 mins to fix
              api/auth/authproviders.py on lines 63..63
              api/auth/authproviders.py on lines 65..65
              api/auth/authproviders.py on lines 190..190

              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 34.

              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 2 locations. Consider refactoring.
              Open

                      config.db.acquisitions.update({'_id': c['_id']}, {'$set': {'timestamp': utc_timestamp, 'timezone': replace}})
              Severity: Minor
              Found in bin/oneoffs/timezone_shift.py and 1 other location - About 40 mins to fix
              bin/database.py on lines 1369..1369

              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 34.

              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

              Severity
              Category
              Status
              Source
              Language