edgewall/trac

View on GitHub
trac/db/mysql_backend.py

Summary

Maintainability
D
3 days
Test Coverage

File mysql_backend.py has 445 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2005-2023 Edgewall Software
# Copyright (C) 2005-2006 Christopher Lenz <cmlenz@gmx.de>
# Copyright (C) 2005 Jeff Weiss <trac@jeffweiss.org>
Severity: Minor
Found in trac/db/mysql_backend.py - About 6 hrs to fix

    Function __init__ has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, path, log, user=None, password=None, host=None,
                     port=None, params={}):
            if path.startswith('/'):
                path = path[1:]
            if password is None:
    Severity: Minor
    Found in trac/db/mysql_backend.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 backup has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def backup(self, dest_file):
            db_url = self.env.config.get('trac', 'database')
            scheme, db_prop = parse_connection_uri(db_url)
            db_params = db_prop.setdefault('params', {})
            db_name = os.path.basename(db_prop['path'])
    Severity: Minor
    Found in trac/db/mysql_backend.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 drop_column has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def drop_column(self, table, column):
            cursor = pymysql.cursors.Cursor(self.cnx)
            if column in self.get_column_names(table):
                quoted_table = self.quote(table)
                cursor.execute("SHOW INDEX FROM %s" % quoted_table)
    Severity: Minor
    Found in trac/db/mysql_backend.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_db has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def init_db(self, path, schema=None, log=None, user=None, password=None,
    Severity: Major
    Found in trac/db/mysql_backend.py - About 1 hr to fix

      Function get_connection has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def get_connection(self, path, log=None, user=None, password=None,
      Severity: Major
      Found in trac/db/mysql_backend.py - About 50 mins to fix

        Function destroy_db has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def destroy_db(self, path, log=None, user=None, password=None, host=None,
        Severity: Major
        Found in trac/db/mysql_backend.py - About 50 mins to fix

          Function db_exists has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def db_exists(self, path, log=None, user=None, password=None, host=None,
          Severity: Major
          Found in trac/db/mysql_backend.py - About 50 mins to fix

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

                def __init__(self, path, log, user=None, password=None, host=None,
            Severity: Major
            Found in trac/db/mysql_backend.py - About 50 mins to fix

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

                  def to_sql(self, table, max_bytes=None):
                      if max_bytes is None:
                          max_bytes = self._max_bytes(None)
                      sql = ['CREATE TABLE %s (' % _quote(table.name)]
                      coldefs = []
              Severity: Minor
              Found in trac/db/mysql_backend.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 _collist has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _collist(self, table, columns, max_bytes):
                      """Take a list of columns and impose limits on each so that indexing
                      works properly.
              
                      Some Versions of MySQL limit each index prefix to 3072 bytes total,
              Severity: Minor
              Found in trac/db/mysql_backend.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

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

                      for name, (from_, to) in sorted(columns.items()):
                          to = _type_map.get(to, to)
                          if to != _type_map.get(from_, from_):
                              alterations.append((name, to))
              Severity: Major
              Found in trac/db/mysql_backend.py and 1 other location - About 2 hrs to fix
              trac/db/postgres_backend.py on lines 239..242

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

              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:
                          p = Popen(args, env=environ, stderr=PIPE, close_fds=close_fds)
                      except OSError as e:
                          raise TracError(_("Unable to run %(path)s: %(msg)s",
                                            path=self.mysqldump_path,
              Severity: Major
              Found in trac/db/mysql_backend.py and 1 other location - About 2 hrs to fix
              trac/db/postgres_backend.py on lines 274..279

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

              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 p.returncode != 0:
                          raise TracError(_("mysqldump failed: %(msg)s",
                                            msg=to_unicode(errmsg.strip())))
              Severity: Minor
              Found in trac/db/mysql_backend.py and 1 other location - About 45 mins to fix
              trac/db/postgres_backend.py on lines 281..283

              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