queries/tornado_session.py

Summary

Maintainability
D
1 day
Test Coverage

File tornado_session.py has 382 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Tornado Session Adapter

Use Queries asynchronously within the Tornado framework.

Severity: Minor
Found in queries/tornado_session.py - About 5 hrs to fix

    Function _poll_connection has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def _poll_connection(self, fd):
            """Check with psycopg2 to see what action to take. If the state is
            POLL_OK, we should have a pending callback for that fd.
    
            :param int fd: The socket fd for the postgresql connection
    Severity: Minor
    Found in queries/tornado_session.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 _create_connection has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def _create_connection(self, future):
            """Create a new PostgreSQL connection
    
            :param tornado.concurrent.Future future: future for new conn result
    
    
    Severity: Minor
    Found in queries/tornado_session.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 _execute has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def _execute(self, method, query, parameters=None):
            """Issue a query asynchronously on the server, mogrifying the
            parameters against the sql statement and yielding the results
            as a :py:class:`Results <queries.tornado_session.Results>` object.
    
    
    Severity: Minor
    Found in queries/tornado_session.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 __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, uri=session.DEFAULT_URI,
    Severity: Minor
    Found in queries/tornado_session.py - About 35 mins to fix

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

          def _cleanup_fd(self, fd, close=False):
              """Ensure the socket socket is removed from the IOLoop, the
              connection stack, and futures stack.
      
              :param int fd: The fd # to cleanup
      Severity: Minor
      Found in queries/tornado_session.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 2 locations. Consider refactoring.
      Open

              except (psycopg2.Error, psycopg2.Warning) as error:
                  if fd in self._futures and not self._futures[fd].done():
                      self._futures[fd].set_exception(error)
      Severity: Major
      Found in queries/tornado_session.py and 1 other location - About 2 hrs to fix
      queries/tornado_session.py on lines 499..501

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

      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 state == extensions.POLL_OK:
                      if fd in self._futures and not self._futures[fd].done():
                          self._futures[fd].set_result(True)
      Severity: Major
      Found in queries/tornado_session.py and 1 other location - About 2 hrs to fix
      queries/tornado_session.py on lines 495..497

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

      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:
                  cursor.close()
              except (psycopg2.Error, psycopg2.Warning) as error:
                  LOGGER.debug('Error closing the cursor: %s', error)
      Severity: Minor
      Found in queries/tornado_session.py and 1 other location - About 35 mins to fix
      queries/pool.py on lines 167..171

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

      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