scitran/core

View on GitHub
api/dao/containerstorage.py

Summary

Maintainability
F
6 days
Test Coverage

File containerstorage.py has 406 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import datetime

import bson
import copy

Severity: Minor
Found in api/dao/containerstorage.py - About 5 hrs to fix

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

        def update_el(self, _id, payload, unset_payload=None, recursive=False, r_payload=None, replace_metadata=False):
            session = self.get_container(_id)
            if session is None:
                raise APINotFoundException('Could not find session {}'.format(_id))
    
    
    Severity: Minor
    Found in api/dao/containerstorage.py - About 3 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 create_el has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def create_el(self, analysis, parent_type, parent_id, origin, uid=None):
            """
            Create an analysis.
            * Fill defaults if not provided
            * Flatten input filerefs using `FileReference.get_file()`
    Severity: Minor
    Found in api/dao/containerstorage.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 recalc_sessions_compliance has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def recalc_sessions_compliance(self, project_id=None):
            if project_id is None:
                # Recalc all projects
                projects = self.get_all_el({'template': {'$exists': True}}, None, None)
            else:
    Severity: Minor
    Found in api/dao/containerstorage.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 recalc_session_compliance has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def recalc_session_compliance(self, session_id, session=None, template=None, hard=False):
            """
            Calculates a session's compliance with the project's session template.
            Returns True if the status changed, False otherwise
            """
    Severity: Minor
    Found in api/dao/containerstorage.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 get_all_el has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_all_el(self, query, user, projection, fill_defaults=False):
            if query is None:
                query = {}
            if user:
                if query.get('permissions'):
    Severity: Minor
    Found in api/dao/containerstorage.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_el has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def update_el(self, _id, payload, unset_payload=None, recursive=False, r_payload=None, replace_metadata=False):
    Severity: Minor
    Found in api/dao/containerstorage.py - About 45 mins to fix

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

          def update_el(self, _id, payload, unset_payload=None, recursive=False, r_payload=None, replace_metadata=False):
      Severity: Minor
      Found in api/dao/containerstorage.py - About 45 mins to fix

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

            def update_el(self, _id, payload, unset_payload=None, recursive=False, r_payload=None, replace_metadata=False):
        Severity: Minor
        Found in api/dao/containerstorage.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

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

              def create_el(self, analysis, parent_type, parent_id, origin, uid=None):
          Severity: Minor
          Found in api/dao/containerstorage.py - About 35 mins to fix

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

                def get_all_for_targets(self, target_type, target_ids, user=None, projection=None, collection_id=None):
            Severity: Minor
            Found in api/dao/containerstorage.py - About 35 mins to fix

              Function inflate_job_info has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def inflate_job_info(self, analysis):
                      """
                      Inflate job from id ref in analysis
              
                      Lookup job via id stored on analysis
              Severity: Minor
              Found in api/dao/containerstorage.py - About 25 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

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

                      if query and query.get('collections'):
                          # Find acquisition ids in this collection, add to query
                          collection_id = query.pop('collections')
                          a_ids = AcquisitionStorage().get_all_el({'collections': bson.ObjectId(collection_id)}, None, {'session': 1})
                          query['_id'] = {'$in': list(set([a['session'] for a in a_ids]))}
              Severity: Major
              Found in api/dao/containerstorage.py and 1 other location - About 5 hrs to fix
              api/dao/containerstorage.py on lines 276..280

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

              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 query and query.get('collections'):
                          # Find acquisition ids in this collection, add to query
                          collection_id = query.pop('collections')
                          a_ids = AcquisitionStorage().get_all_el({'collections': bson.ObjectId(collection_id)}, None, {'session': 1})
                          query['_id'] = {'$in': list(set([a['session'] for a in a_ids]))}
              Severity: Major
              Found in api/dao/containerstorage.py and 1 other location - About 5 hrs to fix
              api/dao/containerstorage.py on lines 144..148

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

              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

                  def get_parent(self, _id, cont=None, projection=None):
                      if not cont:
                          cont = self.get_container(_id, projection=projection)
              
                      ps = ContainerStorage.factory(cont['parent']['type'])
              Severity: Major
              Found in api/dao/containerstorage.py and 1 other location - About 3 hrs to fix
              api/dao/containerstorage.py on lines 434..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 72.

              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

                  def get_parent_tree(self, _id, cont=None, projection=None, add_self=False):
                      if not cont:
                          cont = self.get_container(_id, projection=projection)
              
                      ps = ContainerStorage.factory(cont['parent']['type'])
              Severity: Major
              Found in api/dao/containerstorage.py and 1 other location - About 3 hrs to fix
              api/dao/containerstorage.py on lines 427..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 72.

              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 user:
                          if query.get('permissions'):
                              query['$and'] = [{'permissions': {'$elemMatch': user}}, {'permissions': query.pop('permissions')}]
                          else:
                              query['permissions'] = {'$elemMatch': user}
              Severity: Major
              Found in api/dao/containerstorage.py and 1 other location - About 3 hrs to fix
              api/dao/basecontainerstorage.py on lines 292..296

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

              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 sibling_session:
                              payload['subject']['_id'] = sibling_session.get('subject').get('_id')
                          else:
                              payload['subject']['_id'] = bson.ObjectId()
              Severity: Major
              Found in api/dao/containerstorage.py and 1 other location - About 2 hrs to fix
              api/dao/containerstorage.py on lines 230..233

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

              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 sibling_session:
                              payload['subject']['_id'] = sibling_session.get('subject').get('_id')
                          else:
                              payload['subject']['_id'] = bson.ObjectId()
              Severity: Major
              Found in api/dao/containerstorage.py and 1 other location - About 2 hrs to fix
              api/dao/containerstorage.py on lines 211..214

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

              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 project.get('template'):
                          payload['project_has_template'] = True
                          payload['satisfies_template'] = hierarchy.is_session_compliant(payload, project.get('template'))
              Severity: Minor
              Found in api/dao/containerstorage.py and 1 other location - About 50 mins to fix
              api/dao/containerstorage.py on lines 252..254

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

              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 project and project.get('template'):
                              payload['project_has_template'] = True
                              payload['satisfies_template'] = hierarchy.is_session_compliant(session, project.get('template'))
              Severity: Minor
              Found in api/dao/containerstorage.py and 1 other location - About 50 mins to fix
              api/dao/containerstorage.py on lines 196..198

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

              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

                  def __init__(self):
                      super(ProjectStorage,self).__init__('projects', use_object_id=True, use_delete_tag=True, parent_cont_name='group', child_cont_name='subject')
              Severity: Minor
              Found in api/dao/containerstorage.py and 1 other location - About 35 mins to fix
              api/dao/containerstorage.py on lines 183..184

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

                  def __init__(self):
                      super(SessionStorage,self).__init__('sessions', use_object_id=True, use_delete_tag=True, parent_cont_name='subject', child_cont_name='acquisition')
              Severity: Minor
              Found in api/dao/containerstorage.py and 1 other location - About 35 mins to fix
              api/dao/containerstorage.py on lines 51..52

              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