sqlalchemy.event.remove

Here are the examples of the python api sqlalchemy.event.remove taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

33 Examples 7

Example 1

Project: sqlalchemy-media
Source File: stores.py
View license
    def unbind_events(self) -> None:
        """
        Opposite of :meth:`bind_events`.

        """
        event.remove(self.session, 'after_commit', self.on_commit)
        event.remove(self.session, 'after_soft_rollback', self.on_rollback)
        event.remove(self.session, 'persistent_to_deleted', self.on_delete)

Example 2

Project: SickGear
Source File: fixtures.py
View license
    def teardown(self):
        for key in self._event_fns:
            event.remove(*key)
        super_ = super(RemovesEvents, self)
        if hasattr(super_, "teardown"):
            super_.teardown()

Example 3

Project: SickRage
Source File: fixtures.py
View license
    def teardown(self):
        for key in self._event_fns:
            event.remove(*key)
        super_ = super(RemovesEvents, self)
        if hasattr(super_, "teardown"):
            super_.teardown()

Example 4

Project: moviegrabber
Source File: fixtures.py
View license
    def teardown(self):
        for key in self._event_fns:
            event.remove(*key)
        super_ = super(RemovesEvents, self)
        if hasattr(super_, "teardown"):
            super_.teardown()

Example 5

Project: sqlalchemy
Source File: fixtures.py
View license
    def teardown(self):
        for key in self._event_fns:
            event.remove(*key)
        super_ = super(RemovesEvents, self)
        if hasattr(super_, "teardown"):
            super_.teardown()

Example 6

Project: sqlalchemy
Source File: test_events.py
View license
    def test_no_remove_in_event(self):
        Target = self._fixture()

        t1 = Target()

        def evt():
            event.remove(t1, "event_one", evt)

        event.listen(t1, "event_one", evt)

        assert_raises_message(
            Exception,
            "deque mutated during iteration",
            t1.dispatch.event_one
        )

Example 7

Project: freight
Source File: cases.py
View license
    @pytest.fixture(autouse=True)
    def __transactions(self, request, app):
        def unregister_listener():
            event.remove(Session, "after_transaction_end", self.__restart_savepoint)

        event.listen(Session, "after_transaction_end", self.__restart_savepoint)
        request.addfinalizer(unregister_listener)

        db.session.begin_nested()
        request.addfinalizer(db.session.remove)

Example 8

Project: kokoropy
Source File: fixtures.py
View license
    def teardown(self):
        for key in self._event_fns:
            event.remove(*key)
        super_ = super(RemovesEvents, self)
        if hasattr(super_, "teardown"):
            super_.teardown()

Example 9

Project: ctfscoreboard
Source File: base.py
View license
    def __exit__(self, exc_type, exc_value, exc_traceback):
        event.remove(*self._sql_listen_args)
        if exc_type is not None:
            return False
        if self.test_id:
            limit_msg = (' Limit: %d.' % self.max_count) if self.max_count is not None else ''
            logging.info('%s executed %d queries.%s', self.test_id, len(self.queries), limit_msg)
        if self.max_count is None:
            return
        if len(self.queries) > self.max_count:
            message = ('Maximum query count exceeded: limit %d, executed %d.\n'
                       '----QUERIES----\n%s\n----END----') % (
                            self.max_count, len(self.queries), '\n'.join(self.queries))
            raise AssertionError(message)

Example 10

Project: sqlalchemy-continuum
Source File: manager.py
View license
    def remove_class_configuration_listeners(self, mapper):
        """
        Remove versioning class configuration listeners from specified mapper.

        :param mapper:
            mapper to remove class configuration listeners from
        """
        for event_name, listener in self.class_config_listeners.items():
            sa.event.remove(mapper, event_name, listener)

Example 11

Project: sqlalchemy-continuum
Source File: manager.py
View license
    def remove_operations_tracking(self, mapper):
        """
        Remove listeners from specified mapper that track SQL inserts, updates
        and deletes.

        :param mapper:
            mapper to remove the SQL operations tracking listeners from
        """
        for event_name, listener in self.mapper_listeners.items():
            sa.event.remove(mapper, event_name, listener)

Example 12

Project: sqlalchemy-continuum
Source File: manager.py
View license
    def remove_session_tracking(self, session):
        """
        Remove listeners that track the operations (flushing, committing and
        rolling back) of given session. This method should be used in
        conjuction with `remove_operations_tracking`.

        :param session:
            SQLAlchemy session to remove the operations tracking from
        """
        for event_name, listener in self.session_listeners.items():
            sa.event.remove(session, event_name, listener)

Example 13

Project: sqlalchemy-continuum
Source File: manager.py
View license
    def remove_class_configuration_listeners(self, mapper):
        """
        Remove versioning class configuration listeners from specified mapper.

        :param mapper:
            mapper to remove class configuration listeners from
        """
        for event_name, listener in self.class_config_listeners.items():
            sa.event.remove(mapper, event_name, listener)

Example 14

Project: sqlalchemy-continuum
Source File: manager.py
View license
    def remove_operations_tracking(self, mapper):
        """
        Remove listeners from specified mapper that track SQL inserts, updates
        and deletes.

        :param mapper:
            mapper to remove the SQL operations tracking listeners from
        """
        for event_name, listener in self.mapper_listeners.items():
            sa.event.remove(mapper, event_name, listener)

Example 15

Project: sqlalchemy-continuum
Source File: manager.py
View license
    def remove_session_tracking(self, session):
        """
        Remove listeners that track the operations (flushing, committing and
        rolling back) of given session. This method should be used in
        conjuction with `remove_operations_tracking`.

        :param session:
            SQLAlchemy session to remove the operations tracking from
        """
        for event_name, listener in self.session_listeners.items():
            sa.event.remove(session, event_name, listener)

Example 16

Project: flask-sqlalchemy
Source File: __init__.py
View license
    @classmethod
    def unregister(cls, session):
        if hasattr(session, '_model_changes'):
            del session._model_changes

        event.remove(session, 'before_flush', cls.record_ops)
        event.remove(session, 'before_commit', cls.record_ops)
        event.remove(session, 'before_commit', cls.before_commit)
        event.remove(session, 'after_commit', cls.after_commit)
        event.remove(session, 'after_rollback', cls.after_rollback)

Example 17

Project: flask-sqlalchemy
Source File: __init__.py
View license
    @classmethod
    def unregister(cls, session):
        if hasattr(session, '_model_changes'):
            del session._model_changes

        event.remove(session, 'before_flush', cls.record_ops)
        event.remove(session, 'before_commit', cls.record_ops)
        event.remove(session, 'before_commit', cls.before_commit)
        event.remove(session, 'after_commit', cls.after_commit)
        event.remove(session, 'after_rollback', cls.after_rollback)

Example 18

Project: flask-dance
Source File: test_sqla.py
View license
    def __exit__(self, exc_type, exc_value, traceback):
        event.remove(self.target, self.identifier, self.record_query)

Example 19

Project: sqlalchemy_mptt
Source File: __init__.py
View license
    def stop_query_counter(self):
        event.remove(self.session.bind.engine, "before_cursor_execute",
                     self.catch_queries)

Example 20

View license
def turn_off_sqlalchemy_events():
    models = get_all_refresh_mixin_models()
    for model in models:
        for event in LISTEN_FOR_EVENTS:
            sqlalchemy.event.remove(model, event, model.event_handler)

Example 21

View license
def disable_listeners():
    from autonomie.models.task.task import Task, cache_amounts
    sa.event.remove(Task, "before_insert", cache_amounts)
    sa.event.remove(Task, "before_update", cache_amounts)

Example 22

Project: flask-restless
Source File: helpers.py
View license
def unregister_fsa_session_signals():
    """Unregisters Flask-SQLAlchemy session commit and rollback signal
    handlers.

    When a Flask-SQLAlchemy object is created, it registers signal handlers for
    ``before_commit``, ``after_commit``, and ``after_rollback`` signals. In
    case of using both a plain SQLAlchemy session and a Flask-SQLAlchemy
    session (as is happening in the tests in this package), we need to
    unregister handlers or there will be some exceptions during test
    executions like::

        AttributeError: 'Session' object has no attribute '_model_changes'

    """
    # We don't need to do this if Flask-SQLAlchemy is not installed.
    if not has_flask_sqlalchemy:
        return
    # We don't need to do this if Flask-SQLAlchemy version 2.0 or
    # greater is installed.
    version = parse_version(flask_sqlalchemy.__version__)
    if version >= (2, 0):
        return
    events = flask_sqlalchemy._SessionSignalEvents
    signal_names = ('before_commit', 'after_commit', 'after_rollback')
    for signal_name in signal_names:
        # For Flask-SQLAlchemy version less than 3.0.
        signal = getattr(events, 'session_signal_{0}'.format(signal_name))
        event.remove(SessionBase, signal_name, signal)

Example 23

Project: flask-restless
Source File: helpers.py
View license
def unregister_fsa_session_signals():
    """Unregisters Flask-SQLAlchemy session commit and rollback signal
    handlers.

    When a Flask-SQLAlchemy object is created, it registers signal handlers for
    ``before_commit``, ``after_commit``, and ``after_rollback`` signals. In
    case of using both a plain SQLAlchemy session and a Flask-SQLAlchemy
    session (as is happening in the tests in this package), we need to
    unregister handlers or there will be some exceptions during test
    executions like::

        AttributeError: 'Session' object has no attribute '_model_changes'

    """
    # We don't need to do this if Flask-SQLAlchemy is not installed.
    if not has_flask_sqlalchemy:
        return
    # We don't need to do this if Flask-SQLAlchemy version 2.0 or
    # greater is installed.
    version = parse_version(flask_sqlalchemy.__version__)
    if version >= (2, 0):
        return
    events = flask_sqlalchemy._SessionSignalEvents
    signal_names = ('before_commit', 'after_commit', 'after_rollback')
    for signal_name in signal_names:
        # For Flask-SQLAlchemy version less than 3.0.
        signal = getattr(events, 'session_signal_{0}'.format(signal_name))
        event.remove(SessionBase, signal_name, signal)

Example 24

Project: postgresql-audit
Source File: base.py
View license
    def remove_table_listeners(self):
        for values in self.table_listeners['transaction']:
            sa.event.remove(self.transaction_cls.__table__, *values)
        for values in self.table_listeners['activity']:
            sa.event.remove(self.activity_cls.__table__, *values)

Example 25

Project: postgresql-audit
Source File: base.py
View license
    def remove_listeners(self):
        self.remove_table_listeners()
        for listener in self.listeners:
            sa.event.remove(*listener)

Example 26

Project: postgresql-audit
Source File: base.py
View license
    def remove_table_listeners(self):
        for values in self.table_listeners['transaction']:
            sa.event.remove(self.transaction_cls.__table__, *values)
        for values in self.table_listeners['activity']:
            sa.event.remove(self.activity_cls.__table__, *values)

Example 27

Project: postgresql-audit
Source File: base.py
View license
    def remove_listeners(self):
        self.remove_table_listeners()
        for listener in self.listeners:
            sa.event.remove(*listener)

Example 28

Project: sqlalchemy-searchable
Source File: __init__.py
View license
    def attach_ddl_listeners(self):
        # Remove all previously added listeners, so that same listener don't
        # get added twice in situations where class configuration happens in
        # multiple phases (issue #31).
        for listener in self.listeners:
            event.remove(*listener)
        self.listeners = []

        for column in self.processed_columns:
            # This sets up the trigger that keeps the tsvector column up to
            # date.
            if column.type.columns:
                table = column.table
                if self.option(column, 'remove_symbols'):
                    self.add_listener((
                        table,
                        'after_create',
                        self.search_function_ddl(column)
                    ))
                    self.add_listener((
                        table,
                        'after_drop',
                        DDL(str(DropSearchFunctionSQL(column)))
                    ))

                self.add_listener((
                    table,
                    'after_create',
                    self.search_trigger_ddl(column)
                ))

Example 29

Project: sqlalchemy-searchable
Source File: __init__.py
View license
    def attach_ddl_listeners(self):
        # Remove all previously added listeners, so that same listener don't
        # get added twice in situations where class configuration happens in
        # multiple phases (issue #31).
        for listener in self.listeners:
            event.remove(*listener)
        self.listeners = []

        for column in self.processed_columns:
            # This sets up the trigger that keeps the tsvector column up to
            # date.
            if column.type.columns:
                table = column.table
                if self.option(column, 'remove_symbols'):
                    self.add_listener((
                        table,
                        'after_create',
                        self.search_function_ddl(column)
                    ))
                    self.add_listener((
                        table,
                        'after_drop',
                        DDL(str(DropSearchFunctionSQL(column)))
                    ))

                self.add_listener((
                    table,
                    'after_create',
                    self.search_trigger_ddl(column)
                ))

Example 30

Project: sqlalchemy-utils
Source File: observer.py
View license
    def remove_listeners(self):
        for args in self.listener_args:
            sa.event.remove(*args)

Example 31

Project: sqlalchemy-utils
Source File: observer.py
View license
    def remove_listeners(self):
        for args in self.listener_args:
            sa.event.remove(*args)

Example 32

Project: mediadrop
Source File: middleware.py
View license
    def tear_down(self):
        pool = self._pool()
        for target, fn in self.pool_listeners.items():
            sqlalchemy.event.remove(pool, target, fn)

Example 33

Project: mediadrop
Source File: middleware.py
View license
    def tear_down(self):
        pool = self._pool()
        for target, fn in self.pool_listeners.items():
            sqlalchemy.event.remove(pool, target, fn)