Changeset 886 for trunk


Ignore:
Timestamp:
Sep 8, 2016, 12:04:53 PM (3 years ago)
Author:
cito
Message:

Fix infinite recursion issue

The getattr method assumes that the "db" attribute is always set
(either to None or to the underlying connection). We ensure this
by setting the class attribute "db" to None.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/contents/changelog.rst

    r884 r886  
    11ChangeLog
    22=========
     3
     4Version 5.0.2 (2016-09-08)
     5--------------------------
     6- Fixed an infinite recursion problem in the DB wrapper class of the classic
     7  module that could occur when the underlying connection could not be properly
     8  opened (bug report by Justin Pryzby).
    39
    410Version 5.0.1 (2016-08-18)
  • trunk/pg.py

    r883 r886  
    13581358class DB:
    13591359    """Wrapper class for the _pg connection type."""
     1360
     1361    db = None  # invalid fallback for underlying connection
    13601362
    13611363    def __init__(self, *args, **kw):
  • trunk/tests/test_classic_dbwrapper.py

    r883 r886  
    165165            method = getattr(a, method)
    166166            self.assertRaises(TypeError, method, a)
     167
     168
     169class TestDBClassInit(unittest.TestCase):
     170    """Test proper handling of errors when creating DB instances."""
     171
     172    def testBadParams(self):
     173        self.assertRaises(TypeError, pg.DB, invalid=True)
     174
     175    def testDeleteDb(self):
     176        db = DB()
     177        del db.db
     178        self.assertRaises(pg.InternalError, db.close)
     179        del db
    167180
    168181
Note: See TracChangeset for help on using the changeset viewer.