Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-14 Thread Mike Bayer
uot;, echo=True) >> Base.metadata.drop_all(e) >> Base.metadata.create_all(e) >> >> s = Session(e) >> >> c1 = Chain() >> m1 = Molecule(chain=c1) >> r1 = RelatedToChain() >> c1.related.append(r1) >> >> s.add_all([c1, m1, r1]) >&g

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-14 Thread Mark Aquino
) > r1 = RelatedToChain() > c1.related.append(r1) > > s.add_all([c1, m1, r1]) > s.commit() > > > s.delete(c1) > s.commit() > > > > > > > > > > > > > It works as expected with deleting the molecule, and test_molecule_chain > rows are remo

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-14 Thread Mike Bayer
to > any test_molecules anymore. Am I doing something differently in my > test_molecule configuration that I’m just not seeing? > > Mark Aquino > > *From:* sqlalchemy@googlegroups.com on behalf > of Mike Bayer > *Sent:* Wednesday, April 14, 2021 11:21:28 AM > *T

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-14 Thread Mark Aquino
of Mike Bayer Sent: Wednesday, April 14, 2021 11:21:28 AM To: noreply-spamdigest via sqlalchemy Subject: Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation hey there- The general strategy, if you want to write business logic that checks things, takes other actions,

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-14 Thread Mike Bayer
hey there- The general strategy, if you want to write business logic that checks things, takes other actions, etc. when changes occur in the session, is to use the before_flush event handler:

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-13 Thread Mark Aquino
Hi Mike, Sorry about the indentations. I'm not sure I understand the changes you made to the script after delete as it removes all test_chains, test_var_regions, and test_const regions that are still referenced by the other test_molecules. The only way I've been able to get the delete to work

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-13 Thread Mike Bayer
Hi there - I would ask that you try to make sure your formatting is maintained when posting examples especially such long ones as I had to re-indent it in order to run this. The delete at the end is failing because of incomplete cascade rules. The DELETE against "test_mol_sequence" seeks to

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-13 Thread Mark Aquino
I just wanted to clarify, the desire would be for the "test_var_region" and "test_const_region" entities that are linked to other entities to remain untouched and only to have their associations removed from the deleted items. The output from the ORM indicates that the system is actually

[sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-13 Thread maqui...@gmail.com
I need to delete the association table rows for many to many relationships when I delete one, but the default behavior (to remove those rows) does not seem to work in my case. I have multiple levels of many to many relationships, as you can see in the example I'll provide below and when I