scitran/core

View on GitHub
api/jobs/handlers.py

Summary

Maintainability
F
1 wk
Test Coverage

File handlers.py has 533 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
API request handlers for the jobs module
"""
import bson
import copy
Severity: Major
Found in api/jobs/handlers.py - About 1 day to fix

    Function get_config has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_config(self, _id):
            """Get a job's config"""
            j = Job.get(_id)
            c = j.config
            if c is None:
    Severity: Minor
    Found in api/jobs/handlers.py - About 4 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 post has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        def post(self):
            """
            Create a batch job proposal, insert as 'pending' if there are matched containers
            """
    
    
    Severity: Minor
    Found in api/jobs/handlers.py - About 4 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 suggest has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def suggest(self, _id, cont_name, cid):
            """
            Given a container reference, return display information about parents, children and files
            as well as information about which best match each gear input
    
    
    Severity: Minor
    Found in api/jobs/handlers.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 put has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def put(self, _id):
            """
            Update a job. Updates timestamp.
            Enforces a valid state machine transition, if any.
            Rejects any change to a job that is not currently in 'pending' or 'running' state.
    Severity: Minor
    Found in api/jobs/handlers.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 post has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def post(self):
            """
            Create a batch job proposal, insert as 'pending' if there are matched containers
            """
    
    
    Severity: Minor
    Found in api/jobs/handlers.py - About 1 hr to fix

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

          def put(self, cid, rid):
              """Change a rule"""
      
              if cid == 'site':
                  if not self.user_is_admin:
      Severity: Minor
      Found in api/jobs/handlers.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

      Avoid deeply nested control flow statements.
      Open

                              if c.get('inputs') is None:
                                  c['inputs'] = {}
      
      
      Severity: Major
      Found in api/jobs/handlers.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if j.origin['type'] != 'user':
                                    raise Exception('Cannot provide an API key to a job not launched by a user')
        
        
        Severity: Major
        Found in api/jobs/handlers.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if parsed_url.port != 443:
                                      api_key = parsed_url.hostname + ':' + str(parsed_url.port) + ':' + api_key
                                  else:
                                      api_key = parsed_url.hostname + ':' + api_key
          
          
          Severity: Major
          Found in api/jobs/handlers.py - About 45 mins to fix

            Function delete has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def delete(self, cid, rid):
                    """Remove a rule"""
            
                    if cid == 'site':
                        if not self.user_is_admin:
            Severity: Minor
            Found in api/jobs/handlers.py - About 35 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 post has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def post(self, cid):
                    """Add a rule"""
            
                    if cid == 'site':
                        if not self.user_is_admin:
            Severity: Minor
            Found in api/jobs/handlers.py - About 35 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 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def get(self, cid, rid):
                    """Get rule"""
            
                    projection = None
                    if cid == 'site':
            Severity: Minor
            Found in api/jobs/handlers.py - About 35 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 _log_read_check has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def _log_read_check(self, _id):
                    try:
                        job = Job.get(_id)
                    except Exception: # pylint: disable=broad-except
                        self.abort(404, 'Job not found')
            Severity: Minor
            Found in api/jobs/handlers.py - About 35 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 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get(self, cid):
                    """List rules"""
            
                    projection = None
            
            
            Severity: Minor
            Found in api/jobs/handlers.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 cid == 'site':
                        if self.public_request:
                            raise APIPermissionException('Viewing site-level rules requires login.')
                        projection = {'project_id': 0}
                    else:
            Severity: Major
            Found in api/jobs/handlers.py and 1 other location - About 5 hrs to fix
            api/jobs/handlers.py on lines 240..247

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

            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 cid == 'site':
                        if self.public_request:
                            raise APIPermissionException('Viewing site-level rules requires login.')
                        projection = {'project_id': 0}
                    else:
            Severity: Major
            Found in api/jobs/handlers.py and 1 other location - About 5 hrs to fix
            api/jobs/handlers.py on lines 197..204

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

            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 cid == 'site':
                        if not self.user_is_admin:
                            raise APIPermissionException('Modifying site-level rules can only be done by a site admin.')
                    else:
                        project = ProjectStorage().get_container(cid, projection={'permissions': 1})
            Severity: Major
            Found in api/jobs/handlers.py and 2 other locations - About 4 hrs to fix
            api/jobs/handlers.py on lines 212..218
            api/jobs/handlers.py on lines 289..295

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

            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 cid == 'site':
                        if not self.user_is_admin:
                            raise APIPermissionException('Adding site-level rules can only be done by a site admin.')
                    else:
                        project = ProjectStorage().get_container(cid, projection={'permissions': 1})
            Severity: Major
            Found in api/jobs/handlers.py and 2 other locations - About 4 hrs to fix
            api/jobs/handlers.py on lines 261..267
            api/jobs/handlers.py on lines 289..295

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

            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 cid == 'site':
                        if not self.user_is_admin:
                            raise APIPermissionException('Modifying site-level rules can only be done by a site admin.')
                    else:
                        project = ProjectStorage().get_container(cid, projection={'permissions': 1})
            Severity: Major
            Found in api/jobs/handlers.py and 2 other locations - About 4 hrs to fix
            api/jobs/handlers.py on lines 212..218
            api/jobs/handlers.py on lines 261..267

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

            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

                        response['children']['subjects'] = [{'cont_type': 'subject', '_id': c['_id'], 'label': c.get('label', '')} for c in children]
            Severity: Major
            Found in api/jobs/handlers.py and 1 other location - About 1 hr to fix
            api/jobs/handlers.py on lines 110..110

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

            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

                        response['children']['analyses'] = [{'cont_type': 'analysis', '_id': a['_id'], 'label': a.get('label', '')} for a in analyses]
            Severity: Major
            Found in api/jobs/handlers.py and 1 other location - About 1 hr to fix
            api/jobs/handlers.py on lines 125..125

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

            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 updates.get('alg'):
                        try:
                            get_gear_by_name(updates['alg'])
                        except APINotFoundException:
                            self.abort(400, 'Cannot find gear for alg {}, alg not valid'.format(updates['alg']))
            Severity: Major
            Found in api/jobs/handlers.py and 1 other location - About 1 hr to fix
            api/jobs/handlers.py on lines 224..227

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

            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

                    try:
                        get_gear_by_name(payload['alg'])
                    except APINotFoundException:
                        self.abort(400, 'Cannot find gear for alg {}, alg not valid'.format(payload['alg']))
            Severity: Major
            Found in api/jobs/handlers.py and 1 other location - About 1 hr to fix
            api/jobs/handlers.py on lines 277..281

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

            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