django/django

View on GitHub
django/views/debug.py

Summary

Maintainability
F
3 days
Test Coverage

File debug.py has 420 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import functools
import re
import sys
import types
from pathlib import Path
Severity: Minor
Found in django/views/debug.py - About 6 hrs to fix

    Function get_traceback_frame_variables has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_traceback_frame_variables(self, request, tb_frame):
            """
            Replace the values of variables marked as sensitive with
            stars (*********).
            """
    Severity: Minor
    Found in django/views/debug.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 get_traceback_data has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_traceback_data(self):
            """Return a dictionary containing traceback information."""
            if self.exc_type and issubclass(self.exc_type, TemplateDoesNotExist):
                self.template_does_not_exist = True
                self.postmortem = self.exc_value.chain or [self.exc_value]
    Severity: Minor
    Found in django/views/debug.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 get_post_parameters has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_post_parameters(self, request):
            """
            Replace the values of POST parameters marked as sensitive with
            stars (*********).
            """
    Severity: Minor
    Found in django/views/debug.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 get_traceback_frames has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_traceback_frames(self):
            def explicit_or_implicit_cause(exc_value):
                explicit = getattr(exc_value, '__cause__', None)
                implicit = getattr(exc_value, '__context__', None)
                return explicit or implicit
    Severity: Minor
    Found in django/views/debug.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 technical_404_response has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def technical_404_response(request, exception):
        """Create a technical 404 error response. `exception` is the Http404."""
        try:
            error_url = exception.args[0]['path']
        except (IndexError, TypeError, KeyError):
    Severity: Minor
    Found in django/views/debug.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_source has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_source(self, filename, loader, module_name):
            source = None
            if hasattr(loader, 'get_source'):
                try:
                    source = loader.get_source(module_name)
    Severity: Minor
    Found in django/views/debug.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 cleanse_setting has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def cleanse_setting(key, value):
        """
        Cleanse an individual setting key/value of sensitive content. If the value
        is a dictionary, recursively cleanse the keys in that dictionary.
        """
    Severity: Minor
    Found in django/views/debug.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_lines_from_file has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_lines_from_file(self, filename, lineno, context_lines, loader=None, module_name=None):
            """
            Return context_lines before and after lineno from file.
            Return (pre_context_lineno, pre_context, context_line, post_context).
            """
    Severity: Minor
    Found in django/views/debug.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 param in cleansed:
                                cleansed[param] = CLEANSED_SUBSTITUTE
                        return cleansed
    Severity: Major
    Found in django/views/debug.py - About 45 mins to fix

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

          def _get_lines_from_file(self, filename, lineno, context_lines, loader=None, module_name=None):
      Severity: Minor
      Found in django/views/debug.py - About 35 mins to fix

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

            def __init__(self, request, exc_type, exc_value, tb, is_email=False):
        Severity: Minor
        Found in django/views/debug.py - About 35 mins to fix

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

          def technical_500_response(request, exc_type, exc_value, tb, status_code=500):
          Severity: Minor
          Found in django/views/debug.py - About 35 mins to fix

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

                def get_cleansed_multivaluedict(self, request, multivaluedict):
                    """
                    Replace the keys in a MultiValueDict marked as sensitive with stars.
                    This mitigates leaking sensitive POST parameters if something like
                    request.POST['nonexistent_key'] throws an exception (#21098).
            Severity: Minor
            Found in django/views/debug.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

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

                    with Path(CURRENT_DIR, 'templates', 'technical_500.html').open(encoding='utf-8') as fh:
                        t = DEBUG_ENGINE.from_string(fh.read())
            Severity: Major
            Found in django/views/debug.py and 3 other locations - About 45 mins to fix
            django/views/debug.py on lines 339..340
            django/views/debug.py on lines 507..508
            django/views/debug.py on lines 524..525

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

                    with Path(CURRENT_DIR, 'templates', 'technical_500.txt').open(encoding='utf-8') as fh:
                        t = DEBUG_ENGINE.from_string(fh.read())
            Severity: Major
            Found in django/views/debug.py and 3 other locations - About 45 mins to fix
            django/views/debug.py on lines 332..333
            django/views/debug.py on lines 507..508
            django/views/debug.py on lines 524..525

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

                with Path(CURRENT_DIR, 'templates', 'default_urlconf.html').open(encoding='utf-8') as fh:
                    t = DEBUG_ENGINE.from_string(fh.read())
            Severity: Major
            Found in django/views/debug.py and 3 other locations - About 45 mins to fix
            django/views/debug.py on lines 332..333
            django/views/debug.py on lines 339..340
            django/views/debug.py on lines 507..508

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

                with Path(CURRENT_DIR, 'templates', 'technical_404.html').open(encoding='utf-8') as fh:
                    t = DEBUG_ENGINE.from_string(fh.read())
            Severity: Major
            Found in django/views/debug.py and 3 other locations - About 45 mins to fix
            django/views/debug.py on lines 332..333
            django/views/debug.py on lines 339..340
            django/views/debug.py on lines 524..525

            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

            There are no issues that match your filters.

            Category
            Status