Hello!
I'm new to this group and I have a question. 

This is my model:

class Node(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.String(20))
    name = db.Column(db.String(30), nullable=False)
    date_added = db.Column(db.DateTime, default=datetime.now())
    parent_id = db.Column(db.Integer, db.ForeignKey('node.id'), 
nullable=True)
    path = db.Column(db.String(200), default='')
    __mapper_args__ = {'polymorphic_on': type}

class Directory(Node):
    is_root = db.Column(db.Boolean, default=False)
    children = db.relationship(Node, cascade='all, delete, delete-orphan', 
cascade_backrefs=False,
                               backref=db.backref('parent', 
remote_side=[Node.id]))

class Image(Node):
    basename = db.Column(db.String(36))
    extension = db.Column(db.String(5))
    checksum = db.Column(db.String(32))

    __mapper_args__ = {'polymorphic_identity': 'image'}

def remove_file(mapper, connection, target):
    directory = current_app.config['UPLOAD_FOLDER']
    os.remove(os.path.join(directory, target.basename))

event.listen(Image, 'after_delete', remove_file)

When I delete a Directory  I want all the children Images to be deleted as 
well.  
After deleting the Image, the event listener should also delete the correct 
file from the hdd.
When I'm deleting Images one by one the even listener works just fine but 
when I delete a directory with children Images I get this error:

ObjectDeletedError: Instance '<Image at 0x1020c5c90>' has been deleted, or 
its row is otherwise not present.

I realised that it happens only when in the listener I access the 
attributes that are on the Image (like "basename") and not when I access 
the attributes on Node ("name").

I would be very grateful for any help.


-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to