How to use the transaction.abort function in transaction

To help you get started, we’ve selected a few transaction examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zopefoundation / zope.sqlalchemy / src / zope / sqlalchemy / tests.py View on Github external
def tearDown(self):
        transaction.abort()
        bound_metadata1.drop_all()
        bound_metadata2.drop_all()
        orm.clear_mappers()
github Pylons / acidfs / tests / test_functional.py View on Github external
def cleanup():
        transaction.abort()
        shutil.rmtree(tmp)
github VoteIT / voteit.core / voteit / core / scripts / crontick.py View on Github external
worker = ScriptWorker('crontick')
    
    unixnow = timegm(utcnow().timetuple())

    #Find methods to execute and run them
    methods = _find_methods(worker)
    
    for method in methods:
        try:
            method(worker, unixnow)
            transaction.commit()
            print "=== Transaction for %s committed" % method
        except Exception, e:
            worker.logger.exception(e)
            transaction.abort()
            print "=== Transaction for %s aborted" % method
    
    worker.shutdown()
github sernst / Ziggurat / src / ziggurat / view / ZigguratBaseView.py View on Github external
def _handleFinishedCallback(self, request):
        """commit or abort the transaction associated with request"""
        if request.exception is not None:
            transaction.abort()
        else:
            transaction.commit()
github ENCODE-DCC / encoded / src / snowfort / elasticsearch / mpindexer.py View on Github external
def clear_snapshot(signum=None, frame=None):
    global current_xmin_snapshot_id
    if current_xmin_snapshot_id is None:
        return
    transaction.abort()
    manager.pop()
    current_xmin_snapshot_id = None
github plomino / Plomino / src / Products / CMFPlomino / design.py View on Github external
contextual_ps.errors):
                logger.info('python errors at %s in %s: %s' % (
                    str(context),
                    script_id,
                    str(contextual_ps.errors)))

        except Exception, e:
            if ps and getattr(ps, 'errors', None):
                compilation_errors = ps.errors
            logger.info(
                "Plomino Script Exception: %s, %s" % (
                    formula_str,
                    script_id),
                exc_info=True)
            if self.getRequestCache("ABORT_ON_ERROR"):
                transaction.abort()
            raise PlominoScriptException(
                context,
                e,
                formula_str,
                script_id,
                compilation_errors)
        finally:
            request['_plomino_run_as_owner_'] = None
        return result
github opennode / opennode-management / opennode / oms / zodb / db.py View on Github external
retrying = True
                    time.sleep(random.random() * 0.2)
                except ConflictError as e:
                    trace("GOT WRITE CONFLICT IN RW TRANSACT, retrying %s" % i, t, force=True)
                    retrying = True
                    time.sleep(random.random() * 0.2)
                except StorageTransactionError as e:
                    if e.args and e.args[0] == "Duplicate tpc_begin calls for same transaction":
                        # This may happen when an object attached to one connection is used in anther
                        # connection's transaction. Check and compare _p_jar attributes of all objects
                        # involved in this transaction! They all must be the same.
                        trace("DUPLICATE tpc_begin IN RW TRANSACT", t, force=True)
                    raise
                except:
                    trace('ABORT: bad commit attempt', t)
                    transaction.abort()
                    raise
        raise e
github zopefoundation / Zope / src / Testing / ZopeTestCase / base.py View on Github external
def _close(self):
        '''Closes the ZODB connection.'''
        transaction.abort()
        connections.closeAll()
github Nexedi / erp5 / product / CMFActivity / Activity / SQLBase.py View on Github external
except:
          self._log(ERROR, 'Failed to free messages: %r' % to_free_uid_list)
        else:
          self._log(TRACE, 'Freed messages %r' % to_free_uid_list)
      # Abort if something failed.
      if [m for m in message_list if m.getExecutionState() == MESSAGE_NOT_EXECUTED]:
        endTransaction = transaction.abort
      else:
        endTransaction = transaction.commit
      try:
        endTransaction()
      except:
        self._log(WARNING,
          'Failed to end transaction for messages (uid, path, method_id) %r'
          % [(m.uid, m.object_path, m.method_id) for m in message_list])
        if endTransaction == transaction.abort:
          self._log(PANIC, 'Failed to abort executed messages.'
            ' Some objects may be modified accidentally.')
        else:
          try:
            transaction.abort()
          except:
            self._log(PANIC, 'Failed to abort executed messages which also'
              ' failed to commit. Some objects may be modified accidentally.')
            raise
        exc_info = sys.exc_info()
        for m in message_list:
          m.setExecutionState(MESSAGE_NOT_EXECUTED, exc_info, log=False)
        try:
          makeMessageListAvailable([x.uid for x in message_list],
                                   uid_to_duplicate_uid_list_dict)
        except:
github plone / Products.PloneOrg / scripts / catalog_rebuild.py View on Github external
def conflict_safe_catalog_update(self, query, action, threshold,
                                     res_filter=None):
        """Performs an action on objects found with a catalog query
        in a way that tries to minimize conflicts"""
        cat = self._catalog
        brains = cat(query)
        total = len(brains)
        if res_filter is None:
            res_filter = lambda x: True
        # split into filtered sub-lists of size threshold before filtering
        slices = ((o for o in brains[start:end] if res_filter(o))
                    for start, end in izip(xrange(0, total, threshold),
                               xrange(threshold, total+threshold, threshold)))
        # Run an abort here to help avoid conflicts on the first batch
        # resulting from the extended catalog search
        transaction.abort()
        log('Transaction abort after finding all content (%s objects)'%total)
        self.context._p_jar.sync()
        return self._conflict_safe_update(slices, action)