django/django

View on GitHub
django/db/models/query.py

Summary

Maintainability
F
1 wk
Test Coverage

File query.py has 1502 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
The main QuerySet implementation. This provides the public API for the ORM.
"""

import copy
Severity: Major
Found in django/db/models/query.py - About 4 days to fix

    QuerySet has 80 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class QuerySet:
        """Represent a lazy database lookup for a set of objects."""
    
        def __init__(self, model=None, query=None, using=None, hints=None):
            self.model = model
    Severity: Major
    Found in django/db/models/query.py - About 1 day to fix

      Function prefetch_related_objects has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring.
      Open

      def prefetch_related_objects(model_instances, *related_lookups):
          """
          Populate prefetched object caches for a list of model instances based on
          the lookups/Prefetch instances given.
          """
      Severity: Minor
      Found in django/db/models/query.py - About 1 day to fix

      Cognitive Complexity

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

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

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

      Further reading

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

      def prefetch_one_level(instances, prefetcher, lookup, level):
          """
          Helper function for prefetch_related_objects().
      
          Run prefetches on all instances using the prefetcher object,
      Severity: Minor
      Found in django/db/models/query.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 get_prefetcher has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_prefetcher(instance, through_attr, to_attr):
          """
          For the attribute 'through_attr' on the given instance, find
          an object that has a get_prefetch_queryset().
          Return a 4 tuple containing:
      Severity: Minor
      Found in django/db/models/query.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 bulk_update has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def bulk_update(self, objs, fields, batch_size=None):
              """
              Update the given fields in each of the given objects in the database.
              """
              if batch_size is not None and batch_size < 0:
      Severity: Minor
      Found in django/db/models/query.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 annotate has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def annotate(self, *args, **kwargs):
              """
              Return a query set in which the returned objects have been annotated
              with extra data or aggregations.
              """
      Severity: Minor
      Found in django/db/models/query.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 __iter__ has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def __iter__(self):
              queryset = self.queryset
              db = queryset.db
              compiler = queryset.query.get_compiler(using=db)
              # Execute the query. This will also fill compiler.select, klass_info,
      Severity: Minor
      Found in django/db/models/query.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 __getitem__ has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def __getitem__(self, k):
              """Retrieve an item or slice from the set of results."""
              if not isinstance(k, (int, slice)):
                  raise TypeError(
                      'QuerySet indices must be integers or slices, not %s.'
      Severity: Minor
      Found in django/db/models/query.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 values_list has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def values_list(self, *fields, flat=False, named=False):
              if flat and named:
                  raise TypeError("'flat' and 'named' can't be used together.")
              if flat and len(fields) > 1:
                  raise TypeError("'flat' is not valid when values_list is called with more than one field.")
      Severity: Minor
      Found in django/db/models/query.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 bulk_create has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def bulk_create(self, objs, batch_size=None, ignore_conflicts=False):
              """
              Insert each of the instances into the database. Do *not* call
              save() on each of the instances, do not send any pre/post_save
              signals, and do not set the primary key attribute if it is an
      Severity: Minor
      Found in django/db/models/query.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 _batched_insert has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def _batched_insert(self, objs, fields, batch_size, ignore_conflicts=False):
              """
              Helper method for bulk_create() to insert objs one batch at a time.
              """
              if ignore_conflicts and not connections[self.db].features.supports_ignore_conflicts:
      Severity: Minor
      Found in django/db/models/query.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 in_bulk has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def in_bulk(self, id_list=None, *, field_name='pk'):
              """
              Return a dictionary mapping each of the given IDs to the object with
              that ID. If `id_list` isn't provided, evaluate the entire QuerySet.
              """
      Severity: Minor
      Found in django/db/models/query.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 iterator has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def iterator(self):
              # Cache some things for performance reasons outside the loop.
              db = self.db
              compiler = connections[db].ops.compiler('SQLCompiler')(
                  self.query, connections[db], db
      Severity: Minor
      Found in django/db/models/query.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 prefetch_related has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def prefetch_related(self, *lookups):
              """
              Return a new QuerySet instance that will prefetch the specified
              Many-To-One and Many-To-Many related objects when the QuerySet is
              evaluated.
      Severity: Minor
      Found in django/db/models/query.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 __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, raw_query, model=None, query=None, params=None,
      Severity: Major
      Found in django/db/models/query.py - About 50 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if through_attr in getattr(obj, '_prefetched_objects_cache', ()):
                                # If related objects have been prefetched, use the
                                # cache rather than the object's through_attr.
                                new_obj = list(obj._prefetched_objects_cache.get(through_attr))
                            else:
        Severity: Major
        Found in django/db/models/query.py - About 45 mins to fix

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

              def get(self, *args, **kwargs):
                  """
                  Perform the query and return a single object matching the given
                  keyword arguments.
                  """
          Severity: Minor
          Found in django/db/models/query.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 new_obj is None:
                                  continue
                              # We special-case `list` rather than something more generic
                              # like `Iterable` because we don't want to accidentally match
                              # user models that define __iter__.
          Severity: Major
          Found in django/db/models/query.py - About 45 mins to fix

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

                def _insert(self, objs, fields, return_id=False, raw=False, using=None, ignore_conflicts=False):
            Severity: Minor
            Found in django/db/models/query.py - About 45 mins to fix

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

                  def _extract_model_params(self, defaults, **kwargs):
                      """
                      Prepare `params` for creating a model instance based on the given
                      kwargs; for use by get_or_create() and update_or_create().
                      """
              Severity: Minor
              Found in django/db/models/query.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 isinstance(new_obj, list):
                                      new_obj_list.extend(new_obj)
                                  else:
                                      new_obj_list.append(new_obj)
                              obj_list = new_obj_list
              Severity: Major
              Found in django/db/models/query.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    if isinstance(getattr(instance.__class__, to_attr, None), cached_property):
                                        is_fetched = to_attr in instance.__dict__
                                    else:
                                        is_fetched = hasattr(instance, to_attr)
                                else:
                Severity: Major
                Found in django/db/models/query.py - About 45 mins to fix

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

                      def extra(self, select=None, where=None, params=None, tables=None,
                  Severity: Minor
                  Found in django/db/models/query.py - About 45 mins to fix

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

                        def populate(self, row, from_obj):
                            if self.reorder_for_init:
                                obj_data = self.reorder_for_init(row)
                            else:
                                obj_data = row[self.cols_start:self.cols_end]
                    Severity: Minor
                    Found in django/db/models/query.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 aggregate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def aggregate(self, *args, **kwargs):
                            """
                            Return a dictionary containing the calculations (aggregation)
                            over the current queryset.
                    
                    
                    Severity: Minor
                    Found in django/db/models/query.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 update_or_create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def update_or_create(self, defaults=None, **kwargs):
                            """
                            Look up an object with the given kwargs, updating one with defaults
                            if it exists, otherwise create a new one.
                            Return a tuple (object, created), where created is a boolean
                    Severity: Minor
                    Found in django/db/models/query.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

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

                        def ordered(self):
                            """
                            Return True if the QuerySet is ordered -- i.e. has an order_by()
                            clause or a default ordering on the model (or is empty).
                            """
                    Severity: Minor
                    Found in django/db/models/query.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

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

                        def _create_object_from_params(self, lookup, params, lock=False):
                            """
                            Try to create an object using passed params. Used by get_or_create()
                            and update_or_create().
                            """
                    Severity: Minor
                    Found in django/db/models/query.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

                    There are no issues that match your filters.

                    Category
                    Status