Showing 26 of 26 total issues

File pool.py has 571 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Connection Pooling

"""
import datetime
Severity: Major
Found in queries/pool.py - About 1 day to fix

    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

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

          def query(self, sql, parameters=None):
              """A generator to issue a query on the server, mogrifying the
              parameters against the sql statement. Results are returned as a
              :py:class:`queries.Results` object which can act as an iterator and
              has multiple ways to access the result data.
      Severity: Major
      Found in queries/session.py and 1 other location - About 3 hrs to fix
      queries/session.py on lines 106..130

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

      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 callproc(self, name, args=None):
              """Call a stored procedure on the server, returning the results in a
              :py:class:`queries.Results` instance.
      
              :param str name: The procedure name
      Severity: Major
      Found in queries/session.py and 1 other location - About 3 hrs to fix
      queries/session.py on lines 194..220

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

      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

      File session.py has 285 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      """The Session class allows for a unified (and simplified) view of
      interfacing with a PostgreSQL database server.
      
      Connection details are passed in as a PostgreSQL URI and connections are pooled
      by default, allowing for reuse of connections across modules in the Python
      Severity: Minor
      Found in queries/session.py - About 2 hrs to fix

        Session has 24 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Session(object):
            """The Session class allows for a unified (and simplified) view of
            interfacing with a PostgreSQL database server. The Session object can
            act as a context manager, providing automated cleanup and simple, Pythonic
            way of interacting with the object.
        Severity: Minor
        Found in queries/session.py - About 2 hrs to fix

          Pool has 23 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class Pool(object):
              """A connection pool for gaining access to and managing connections"""
              _lock = threading.Lock()
          
              idle_start = None
          Severity: Minor
          Found in queries/pool.py - About 2 hrs to fix

            PoolManager has 21 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class PoolManager(object):
                """The connection pool object implements behavior around connections and
                their use in queries.Session objects.
            
                We carry a pool id instead of the connection URI so that we will not be
            Severity: Minor
            Found in queries/pool.py - About 2 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

              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 3 locations. Consider refactoring.
              Open

                  @classmethod
                  def set_idle_ttl(cls, pid, ttl):
                      """Set the idle TTL for a pool, after which it will be destroyed.
              
                      :param str pid: The pool id
              Severity: Major
              Found in queries/pool.py and 2 other locations - About 1 hr to fix
              queries/pool.py on lines 453..464
              queries/pool.py on lines 640..650

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

              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

                  @classmethod
                  def set_max_size(cls, pid, size):
                      """Set the maximum number of connections for the specified pool
              
                      :param str pid: The pool to set the size for
              Severity: Major
              Found in queries/pool.py and 2 other locations - About 1 hr to fix
              queries/pool.py on lines 453..464
              queries/pool.py on lines 628..638

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

              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

                  @classmethod
                  def add(cls, pid, connection):
                      """Add a new connection and session to a pool.
              
                      :param str pid: The pool id
              Severity: Major
              Found in queries/pool.py and 2 other locations - About 1 hr to fix
              queries/pool.py on lines 628..638
              queries/pool.py on lines 640..650

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

              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 _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 uri_to_kwargs has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

              def uri_to_kwargs(uri):
                  """Return a URI as kwargs for connecting to PostgreSQL with psycopg2,
                  applying default values for non-specified areas of the URI.
              
                  :param str uri: The connection URI
              Severity: Minor
              Found in queries/utils.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 __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

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

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

                  def uri(host='localhost', port=5432, dbname='postgres', user='postgres',
                  Severity: Minor
                  Found in queries/utils.py - About 35 mins to fix
                    Severity
                    Category
                    Status
                    Source
                    Language