Re: [sqlalchemy] delete of polymorphic objects leaves orphaned parent objects

2019-10-15 Thread natsjoo sodillepa
@Mike @Simon, Thanks guys, I fully understand what you need. However I'm currently very, very busy and just don't have the time. The reason I posted without providing what you need was a little hope that maybe somebody recognized a similar problem. We have around 120 objects and trimming down

Re: [sqlalchemy] delete of polymorphic objects leaves orphaned parent objects

2019-10-14 Thread Mike Bayer
like Simon wrote, we would need more detail on the exact query and how you came up with it, in the original example it refers to an ItemGroup object "ig", is that the object that may have been deleted, is there a stack trace, etc. If you can just put together a script that has the minimal

Re: [sqlalchemy] delete of polymorphic objects leaves orphaned parent objects

2019-10-14 Thread Simon King
I can't make a guess without a script to reproduce it I'm afraid. Sorry, Simon On Mon, Oct 14, 2019 at 8:35 AM natsjoo sodillepa wrote: > > Ok, > > I have managed to get rid of the problem, but I'm don't like what is > happening. > Solution: remove a secondary relation from the model: > >

Re: [sqlalchemy] delete of polymorphic objects leaves orphaned parent objects

2019-10-14 Thread natsjoo sodillepa
Ok, I have managed to get rid of the problem, but I'm don't like what is happening. Solution: remove a secondary relation from the model: model = relationship("Model", secondary='item_group', uselist=False) After this, the following code does do a proper delete of the items: for it in

Re: [sqlalchemy] delete of polymorphic objects leaves orphaned parent objects

2019-10-11 Thread natsjoo sodillepa
Hi Simon, Thank you for your reply. I've tried all the variant I could think of, also eg for item in items: session.delete(it), with and without remove on the list of items, all known mapper and relation params but nothing. However, I've tried a similar structure from examples from the web and

Re: [sqlalchemy] delete of polymorphic objects leaves orphaned parent objects

2019-10-11 Thread Simon King
You haven't given a complete script to reproduce the problem, so I'm not certain what happened. The following is just a guess You are using query(...).delete() with joined-table inheritance, which has a lot of caveats in the docs:

[sqlalchemy] delete of polymorphic objects leaves orphaned parent objects

2019-10-11 Thread natsjoo sodillepa
Hi all, We have a list of polymorphic objects from which delete object does not work, not matter what we try. The situation: class ItemGroup(Base): __tablename__ = 'item_group' __table_args__ = ( UniqueConstraint('model_id', 'item_group_color_id',