datahuborg/datahub

View on GitHub
src/api/serializer.py

Summary

Maintainability
F
6 days
Test Coverage

File serializer.py has 383 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from rest_framework import serializers

from django.contrib.auth.models import User
from django.core.urlresolvers import reverse

Severity: Minor
Found in src/api/serializer.py - About 5 hrs to fix

    Function execute_query has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def execute_query(self, query, current_page=1,
                          rows_per_page=1000, repo=None,
                          rows_only=False):
    
            result = None
    Severity: Minor
    Found in src/api/serializer.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 export_view has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def export_view(self, repo, view, file_name=None, file_format='CSV',
    Severity: Minor
    Found in src/api/serializer.py - About 45 mins to fix

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

          def create_table_from_file(self, repo, table, file_name, delimiter,
      Severity: Minor
      Found in src/api/serializer.py - About 45 mins to fix

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

            def export_table(self, repo, table, file_name=None, file_format='CSV',
        Severity: Minor
        Found in src/api/serializer.py - About 45 mins to fix

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

              def find_security_policies(
          Severity: Minor
          Found in src/api/serializer.py - About 45 mins to fix

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

                def update_card(self, repo, card_name, new_query, new_name, public):
            Severity: Minor
            Found in src/api/serializer.py - About 35 mins to fix

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

                  def create_security_policy(
              Severity: Minor
              Found in src/api/serializer.py - About 35 mins to fix

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

                    def execute_query(self, query, current_page=1,
                Severity: Minor
                Found in src/api/serializer.py - About 35 mins to fix

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

                      def describe_card(
                  Severity: Minor
                  Found in src/api/serializer.py - About 35 mins to fix

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

                    def _unique_keys(proposed):
                        """
                        Uniques and returns a given list of strings.
                    
                        e.g. ['foo', 'foo', 'foo'] => ['foo', 'foo_1', 'foo_2']
                    Severity: Minor
                    Found in src/api/serializer.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

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

                        def list_views(self, repo):
                            views = self.manager.list_views(repo)
                    
                            view_list = []
                            for view in views:
                    Severity: Major
                    Found in src/api/serializer.py and 3 other locations - About 5 hrs to fix
                    src/api/serializer.py on lines 234..246
                    src/api/serializer.py on lines 322..334
                    src/api/serializer.py on lines 387..398

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

                    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

                        def list_tables(self, repo):
                            tables = self.manager.list_tables(repo)
                            table_list = []
                            for table in tables:
                                relative_uri = reverse('api:table', args=(
                    Severity: Major
                    Found in src/api/serializer.py and 3 other locations - About 5 hrs to fix
                    src/api/serializer.py on lines 282..294
                    src/api/serializer.py on lines 322..334
                    src/api/serializer.py on lines 387..398

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

                    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

                        def list_files(self, repo):
                            files = self.manager.list_repo_files(repo)
                            file_list = []
                            for file in files:
                                relative_uri = reverse('api:file', args=(
                    Severity: Major
                    Found in src/api/serializer.py and 3 other locations - About 5 hrs to fix
                    src/api/serializer.py on lines 234..246
                    src/api/serializer.py on lines 282..294
                    src/api/serializer.py on lines 322..334

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

                    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

                        def list_cards(self, repo):
                            cards = self.manager.list_repo_cards(repo)
                    
                            card_list = []
                            for card in cards:
                    Severity: Major
                    Found in src/api/serializer.py and 3 other locations - About 5 hrs to fix
                    src/api/serializer.py on lines 234..246
                    src/api/serializer.py on lines 282..294
                    src/api/serializer.py on lines 387..398

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

                    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

                            for repo in collab_repos:
                                relative_uri = reverse('api:repo', args=(
                                    self.repo_base, repo.repo_name))
                                absolute_uri = self.base_uri + relative_uri
                    
                    
                    Severity: Major
                    Found in src/api/serializer.py and 2 other locations - About 2 hrs to fix
                    src/api/serializer.py on lines 149..157
                    src/api/serializer.py on lines 166..174

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

                    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

                            for repo in public_repos:
                                relative_uri = reverse('api:repo', args=(
                                    repo.repo_base, repo.repo_name))
                                absolute_uri = self.base_uri + relative_uri
                    
                    
                    Severity: Major
                    Found in src/api/serializer.py and 2 other locations - About 2 hrs to fix
                    src/api/serializer.py on lines 132..140
                    src/api/serializer.py on lines 166..174

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

                    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

                            for repo in collab_repos:
                                relative_uri = reverse('api:repo', args=(
                                    repo.repo_base, repo.repo_name))
                                absolute_uri = self.base_uri + relative_uri
                    
                    
                    Severity: Major
                    Found in src/api/serializer.py and 2 other locations - About 2 hrs to fix
                    src/api/serializer.py on lines 132..140
                    src/api/serializer.py on lines 149..157

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

                    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 export_view(self, repo, view, file_name=None, file_format='CSV',
                                        delimiter=',', header=True):
                            file_name = file_name or view
                            self.manager.export_view(
                    Severity: Major
                    Found in src/api/serializer.py and 1 other location - About 2 hrs to fix
                    src/api/serializer.py on lines 268..271

                    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

                        def export_table(self, repo, table, file_name=None, file_format='CSV',
                                         delimiter=',', header=True):
                            file_name = file_name or table
                            self.manager.export_table(
                    Severity: Major
                    Found in src/api/serializer.py and 1 other location - About 2 hrs to fix
                    src/api/serializer.py on lines 312..315

                    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

                            for column in res:
                                response_obj = {}
                                response_obj['column_name'] = column[0]
                                response_obj['data_type'] = column[1]
                                columns.append(response_obj)
                    Severity: Major
                    Found in src/api/serializer.py and 1 other location - About 2 hrs to fix
                    src/api/serializer.py on lines 301..305

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

                    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

                            for column in res:
                                response_obj = {}
                                response_obj['column_name'] = column[0]
                                response_obj['data_type'] = column[1]
                                response.append(response_obj)
                    Severity: Major
                    Found in src/api/serializer.py and 1 other location - About 2 hrs to fix
                    src/api/serializer.py on lines 253..257

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

                    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