How to use the transaction.savepoint 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 collective / collective.lineage / src / collective / lineage / tests.py View on Github external
def run_migration_step(self):
        import transaction
        transaction.savepoint()
        # Now run the migration step
        profile_id = "collective.lineage:default"
        setup_tool = self.layer['portal'].portal_setup
        steps_to_run = _upgrade_registry.getUpgradeStepsForProfile(profile_id)
        for step_id in steps_to_run:
            step = _upgrade_registry.getUpgradeStep(profile_id, step_id)
            if step is not None:
                if step.title == "Migrate the Child Folder objects":
                    step.doStep(setup_tool)
github Nexedi / erp5 / product / ERP5 / Document / BusinessPackage.py View on Github external
def _resetDynamicModules(self):
    # before any import, flush all ZODB caches to force a DB reload
    # otherwise we could have objects trying to get commited while
    # holding reference to a class that is no longer the same one as
    # the class in its import location and pickle doesn't tolerate it.
    # First we do a savepoint to dump dirty objects to temporary
    # storage, so that all references to them can be freed.
    transaction.savepoint(optimistic=True)
    # Then we need to flush from all caches, not only the one from this
    # connection
    portal = self.getPortalObject()
    portal._p_jar.db().cacheMinimize()
    synchronizeDynamicModules(portal, force=True)
    gc.collect()
github Nexedi / erp5 / product / ERP5 / ERP5Site.py View on Github external
def migrateToPortalTypeClass(self):
    # PickleUpdater() will load objects from ZODB, but any objects created
    # before must have been committed (otherwise POSKeyError is raised)
    transaction.savepoint(optimistic=True)

    from Products.ERP5Type.dynamic.persistent_migration import PickleUpdater
    from Products.ERP5Type.Tool.BaseTool import BaseTool
    PickleUpdater(self)
    for tool in self.objectValues():
      if isinstance(tool, BaseTool):
        tool_id = tool.id
        if tool_id not in ('portal_property_sheets', 'portal_components'):
          if tool_id in ('portal_categories', ):
            tool = tool.activate()
          tool.migrateToPortalTypeClass(tool_id not in (
            'portal_activities', 'portal_simulation', 'portal_templates',
            'portal_trash', 'portal_catalog'))
          if tool_id in ('portal_trash', 'portal_catalog'):
            for obj in tool.objectValues():
              obj.migrateToPortalTypeClass()
github mjpieters / collective.transmogrifier / src / collective / transmogrifier / sections / savepoint.py View on Github external
def __iter__(self):
        count = 0
        for item in self.previous:
            count = (count + 1) % self.every
            if count == 0:
                transaction.savepoint(optimistic=True)
            yield item
github plone / plone.app.dexterity / plone / app / dexterity / behaviors / id.py View on Github external
def _set_id(self, value):
        if not value:
            return
        context = aq_inner(self.context)
        parent = aq_parent(context)
        if parent is None:
            # Object hasn't been added to graph yet; just set directly
            context.id = value
            return
        new_id = INameChooser(parent).chooseName(value, context)
        if getattr(aq_base(context), 'id', None):
            transaction.savepoint()
            locked = False
            lockable = ILockable(context, None)
            if lockable is not None and lockable.locked():
                locked = True
                lockable.unlock()
            parent.manage_renameObject(context.getId(), new_id)
            if locked:
                lockable.lock()
        else:
            context.id = new_id
    id = property(_get_id, _set_id)
github plone / Products.Archetypes / Products / Archetypes / BaseObject.py View on Github external
return False

        invalid_id = check_id(self, new_id, required=1)

        # If check_id told us no, or if it was not found, make sure we have an
        # id unique in the parent folder.
        if invalid_id:
            unique_id = self._findUniqueId(new_id)
            if unique_id is not None:
                new_id = unique_id
                invalid_id = False

        if not invalid_id:
            # Can't rename without a subtransaction commit when using
            # portal_factory!
            transaction.savepoint(optimistic=True)
            self.setId(new_id)
            return new_id

        return False
github senaite / senaite.core / bika / lims / jsonapi / create.py View on Github external
>>> browser.open(portal_url+"/@@API/create", "&".join([
        ... "obj_type=AnalysisRequest",
        ... "thing=Fish",
        ... "Client=portal_type:Client|id:client-1",
        ... "SampleType=portal_type:SampleType|title:Apple Pulp",
        ... "Contact=portal_type:Contact|getFullname:Rita Mohale",
        ... "Services:list=portal_type:AnalysisService|title:Calcium",
        ... "Services:list=portal_type:AnalysisService|title:Copper",
        ... "Services:list=portal_type:AnalysisService|title:Magnesium",
        ... "SamplingDate=2013-09-29"
        ... ]))
        >>> browser.contents
        '{...The following request fields were not used: ...thing...}'

        """
        savepoint = transaction.savepoint()
        self.context = context
        self.request = request
        self.unused = [x for x in self.request.form.keys()]
        self.used("form.submitted")
        self.used("__ac_name")
        self.used("__ac_password")
        # always require obj_type
        self.require("obj_type")
        obj_type = self.request['obj_type']
        self.used("obj_type")
        # AnalysisRequest shortcut: creates Sample, Partition, AR, Analyses.
        if obj_type == "AnalysisRequest":
            raise BadRequest("Creation of Analysis Request through JSON API is "
                             "not supported. Request aborted.")
        # Other object types require explicit path as their parent
        self.require("obj_path")
github zopefoundation / Zope / src / Products / ZODBMountPoint / MountedObject.py View on Github external
params = self._loadMountParams()
        real_root, real_path, container_class = params
        if real_root is None:
            real_root = 'Application'
        try:
            obj = root[real_root]
        except KeyError:
            # DM 2005-05-17: why should we require 'container_class'?
            #if container_class or self._create_mount_points:
            if self._create_mount_points:
                # Create a database automatically.
                from OFS.Application import Application
                obj = Application()
                root[real_root] = obj
                # Get it into the database
                transaction.savepoint(optimistic=True)
            else:
                raise

        if real_path is None:
            real_path = self._path
        if real_path and real_path != '/':
            try:
                obj = obj.unrestrictedTraverse(real_path)
            except (KeyError, AttributeError):
                # DM 2005-05-13: obviously, we do not want automatic
                #  construction when "_create_mount_points" is false
                #if container_class or self._create_mount_points:
                if container_class and self._create_mount_points:
                    blazer = CustomTrailblazer(obj, container_class)
                    obj = blazer.traverseOrConstruct(real_path)
                else:
github collective / Products.Poi / Products / Poi / content / PoiIssue.py View on Github external
def _renameAfterCreation(self, check_auto_id=False):
        parent = self.getTracker()
        maxId = 0
        for id in parent.objectIds():
            try:
                intId = int(id)
                maxId = max(maxId, intId)
            except (TypeError, ValueError):
                pass
        newId = str(maxId + 1)
        # Can't rename without a subtransaction commit when using
        # portal_factory!
        transaction.savepoint(optimistic=True)
        self.setId(newId)