Changeset - 19125d2a3ae9
[Not reviewed]
0 4 0
Lance Edgar (lance) - 2 months ago 2024-08-28 00:25:24
lance@edbob.org
fix: move "record changes" global hook to startup()

this silly thing shouldn't even exist but can't remove until i'm
certain it's not in use in the wild.

but at least, it shouldn't be triggered when a config object is
instantiated, it needs to be deferred a little. should not affect app
runtime per se but more helpful for tests.
4 files changed with 15 insertions and 24 deletions:
0 comments (0 inline, 0 general)
rattail/config.py
Show inline comments
 
@@ -102,10 +102,6 @@ class RattailConfig(WuttaConfig):
 
            # TODO: eventually this should not be needed (?)
 
            Session.configure(rattail_config=self)
 

	
 
            # TODO: this should be removed, it sets 'record changes' globally
 
            from rattail.db.config import configure_session
 
            configure_session(self, Session)
 

	
 
    @property
 
    def rattail_engines(self):
 
        warnings.warn("config.rattail_engines is deprecated; "
 
@@ -686,6 +682,14 @@ class RattailConfigExtension(WuttaConfigExtension):
 
        if os.path.isdir(poser) and poser not in sys.path:
 
            sys.path.append(poser)
 

	
 
    def startup(self, config):
 
        from rattail.db import Session
 
        if Session:
 

	
 
            # TODO: this should be removed, it sets 'record changes' globally
 
            from rattail.db.config import configure_session
 
            configure_session(config, Session)
 

	
 

	
 
def rattail_default_files(appname):
 
    """
rattail/db/config.py
Show inline comments
 
@@ -59,13 +59,14 @@ def get_default_engine(config, section='rattail.db'):
 
    return wutta_get_engines(config, section).get('default')
 

	
 

	
 
# TODO: Deprecate/remove this.
 
# TODO: DEPRECATED - this should be removed soon
 
def configure_session(config, session):
 
    """
 
    Configure a session factory or instance.  Currently all this does is
 
    install the hook to record changes, if config so dictates.
 
    """
 
    """ """
 
    if config.getbool('rattail.db', 'changes.record', usedb=False):
 
        warnings.warn("setting rattail.db.changes.record is deprecated; "
 
                      "please set per-engine .record_changes instead",
 
                      DeprecationWarning)
 

	
 
        from rattail.db.changes import record_changes
 
        record_changes(session, config=config)
 

	
rattail/testing.py
Show inline comments
 
@@ -29,6 +29,7 @@ class DataTestCase(FileTestCase):
 

	
 
    def teardown_db(self):
 
        self.teardown_files()
 
        self.session.close()
 

	
 
    def make_config(self, **kwargs):
 
        return RattailConfig(**kwargs)
tests/test_config.py
Show inline comments
 
@@ -41,23 +41,8 @@ class TestRattailConfig(FileConfigTestCase):
 
            'rattail.db.default.url': 'sqlite://',
 
        })
 
        if db.Session:
 
            # nb. "record changes" off by default
 
            self.assertFalse(hasattr(db.Session, 'rattail_record_changes'))
 
            session = db.Session()
 
            self.assertEqual(str(session.bind.url), 'sqlite://')
 
            self.assertFalse(session.rattail_record_changes)
 

	
 
        # with "record changes"
 
        config = self.make_config(defaults={
 
            'rattail.db.default.url': 'sqlite://',
 
            'rattail.db.changes.record': 'true',
 
        })
 
        if db.Session:
 
            self.assertTrue(db.Session.rattail_record_changes)
 
            session = db.Session()
 
            # nb. session instance still does not have the flag
 
            # TODO: is this by design..?  does it need to improve?
 
            self.assertFalse(session.rattail_record_changes)
 

	
 
    def test_prioritized_files(self):
 
        first = self.write_file('first.conf', """\
0 comments (0 inline, 0 general)