Changeset - d36fd56e4b91
[Not reviewed]
0 3 0
Lance Edgar (lance) - 4 years ago 2020-10-13 17:02:57
lance@edbob.org
Allow datasync to export to rattail but *not* record changes

sometimes the "record changes" feature is desirable in all but 1 case, which is
real-time datasync, when such changes are "one way only" and have no need to
boomerang back to the originating system, and trying to do so can result in
misc. race conditions which are better avoided
3 files changed with 10 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rattail/datasync/rattail.py
Show inline comments
 
@@ -321,8 +321,11 @@ class FromRattailToRattailExportConsumer(NewDataSyncImportConsumer):
 
        super(FromRattailToRattailExportConsumer, self).setup()
 
        self.topo_sortkey = make_topo_sortkey(self.model)
 

	
 
    def make_target_session(self):
 
        return Session(bind=self.target_engine)
 

	
 
    def process_changes(self, session, changes):
 
        target_session = Session(bind=self.target_engine)
 
        target_session = self.make_target_session()
 

	
 
        if self.runas_username:
 
            target_session.set_continuum_user(self.runas_username)
rattail/db/__init__.py
Show inline comments
 
@@ -45,7 +45,7 @@ if sqlalchemy:
 
        related to the SQLAlchemy-Continuum integration.
 
        """
 

	
 
        def __init__(self, rattail_config=None, rattail_record_changes=False, continuum_user=None, **kwargs):
 
        def __init__(self, rattail_config=None, rattail_record_changes=None, continuum_user=None, **kwargs):
 
            """
 
            Custom constructor, to allow specifying the Continuum user at session
 
            creation.  If ``continuum_user`` is specified, its value will be passed
 
@@ -55,7 +55,9 @@ if sqlalchemy:
 
            self.rattail_config = rattail_config
 

	
 
            # maybe record changes
 
            if rattail_record_changes or getattr(self.bind, 'rattail_record_changes', False):
 
            if rattail_record_changes is None:
 
                rattail_record_changes = getattr(self.bind, 'rattail_record_changes', False)
 
            if rattail_record_changes:
 
                from rattail.db.changes import record_changes
 
                record_changes(self, config=self.rattail_config)
 
            else:
 
@@ -87,7 +89,7 @@ if sqlalchemy:
 
            self.continuum_user = user
 

	
 

	
 
    Session = orm.sessionmaker(class_=SessionBase, rattail_config=None, rattail_record_changes=False, expire_on_commit=False)
 
    Session = orm.sessionmaker(class_=SessionBase, rattail_config=None, expire_on_commit=False)
 

	
 

	
 
else: # no sqlalchemy
rattail/tests/db/test_init.py
Show inline comments
 
@@ -28,7 +28,7 @@ class TestSession(TestCase):
 

	
 
    def test_init_record_changes(self):
 
        if hasattr(db.Session, 'kw'):
 
            self.assertFalse(db.Session.kw['rattail_record_changes'])
 
            self.assertIsNone(db.Session.kw.get('rattail_record_changes'))
 

	
 
        session = db.Session()
 
        self.assertFalse(session.rattail_record_changes)
0 comments (0 inline, 0 general)