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 mappings in use, and 
a little bit of sample data, and the steps you are doing to get to the query 
that fails, even if the script doesn't reproduce the problem I may be able to 
come up with how it would come to the stack trace you are describing (need that 
too as it shows where the problem originates).





On Mon, Oct 14, 2019, at 3: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:
> 
> model = relationship("Model", secondary='item_group', uselist=False)
> 
> After this, the following code does do a proper delete of the items:
> 
> for it in self.session.query(ItemMeta).filter_by(item_group=item_group).all():
>     if type(it) == ItemMeta:
>         item_group.items.remove(it)
>         self.session.delete(it)
> self.session.commit()
> 
> However, things are still not ideal. The following should work but doesn't:
> 
> for item in item_group.items:
>  self.session.delete(item)
> 
> Then only half of the item get deleted, which is a bit weird.
> 
> Anybody any thoughts on this? Why does a secondary relation of this kind of 
> effect on a delete?
> 
> Kinde regards,
> Nacho
> 

> --
>  SQLAlchemy - 
>  The Python SQL Toolkit and Object Relational Mapper
> 
> http://www.sqlalchemy.org/
> 
>  To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
>  --- 
>  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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/073b7947-ed51-4b63-bfdb-a5499128c06c%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/073b7947-ed51-4b63-bfdb-a5499128c06c%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/63610416-e74e-46b2-967b-4e0d24481340%40www.fastmail.com.

Reply via email to