I'd like to restrict deletion and updates on an object based on the boolean 
attribute 'locked' on the same object.

I've managed to successfully suppress updates but it doesn't seem to work 
for deletes with the following code.

@listen_for(mapper, 'mapper_configured')
def mapper_configured(mapper, cls):
    def extract(obj):
        try: return obj[0]
        except IndexError: return False
    if issubclass(cls, Base):
        @listen_for(cls, 'before_update)
        @listen_for(cls, 'before_delete)
        def restrict(mapper, connection, target):
            session = Session.object_session(target)
            added, unchanged, deleted = map(extract, 
inspect(target).attrs.locked.history)
            if unchanged:
                session.expire(target)

How can I make SA restrict the delete and keep object in database when a 
session.delete(obj) is issued?

Any help appreciated,

Mats

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to