flamingo-run/django-cloud-tasks

View on GitHub

Showing 11 of 11 total issues

File task.py has 324 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import abc
import inspect
from dataclasses import dataclass, fields
from datetime import datetime, timedelta, timezone
from functools import lru_cache
Severity: Minor
Found in django_cloud_tasks/tasks/task.py - About 3 hrs to fix

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

        operations = [
            migrations.CreateModel(
                name="Person",
                fields=[
                    ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
    Severity: Major
    Found in sample_project/sample_app/migrations/0001_initial.py and 1 other location - About 1 hr to fix
    django_cloud_tasks/migrations/0001_initial.py on lines 15..19

    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

            migrations.CreateModel(
                name="Pipeline",
                fields=[
                    ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                    ("name", models.CharField(max_length=100)),
    Severity: Major
    Found in django_cloud_tasks/migrations/0001_initial.py and 1 other location - About 1 hr to fix
    sample_project/sample_app/migrations/0001_initial.py on lines 11..16

    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

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

        def from_headers(cls, headers: dict) -> Self:
            # Available data: https://cloud.google.com/tasks/docs/creating-http-target-tasks#handler
            cloud_tasks_prefix = "X-Cloudtasks-"
            cloud_scheduler_prefix = "X-Cloudscheduler"
    
    
    Severity: Minor
    Found in django_cloud_tasks/tasks/task.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 discard has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def discard(cls, task_id: str | None = None, min_retries: int = 0):
            client = cls._get_tasks_client()
            if task_id:
                task_objects = [client.get_task(queue_name=cls.queue(), task_name=task_id)]
            else:
    Severity: Minor
    Found in django_cloud_tasks/tasks/task.py - About 55 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 initialize_subscribers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize_subscribers(self) -> Tuple[Iterable[str], Iterable[str], Iterable[str]]:
            client = CloudSubscriber()
    
            def _get_subscriptions():
                names = []
    Severity: Minor
    Found in django_cloud_tasks/apps.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 push has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def push(
            cls,
            task_kwargs: dict,
            headers: dict | None = None,
            queue: str | None = None,
    Severity: Minor
    Found in django_cloud_tasks/tasks/task.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

    Avoid too many return statements within this function.
    Open

            return super().default(o)
    Severity: Major
    Found in django_cloud_tasks/serializers.py - About 30 mins to fix

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

          def default(self, o):
              if o is None:
                  return None
              if isinstance(o, datetime):
                  value = assure_tz(o.astimezone())
      Severity: Minor
      Found in django_cloud_tasks/serializers.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 schedule_tasks has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def schedule_tasks(self) -> Tuple[Iterable[str], Iterable[str], Iterable[str]]:
              client = CloudScheduler()
      
              def _get_tasks():
                  names = []
      Severity: Minor
      Found in django_cloud_tasks/apps.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 __eq__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def __eq__(self, other) -> bool:
              if not isinstance(other, TaskMetadata):
                  return False
      
              check_fields = [field.name for field in fields(TaskMetadata)]
      Severity: Minor
      Found in django_cloud_tasks/tasks/task.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

      Severity
      Category
      Status
      Source
      Language