On Aug 16, 2011, at 7:39 PM, Dirk Makowski wrote:

> Slowly I am becoming bald...
> 
> Here is a stand-alone script that reproduces the behaviour. Code is a bit 
> verbose, had copied it from my actual project, and it uses PostgreSQL 
> database, and you have to issue an "CREATE SCHEMA sample" beforehand. Sorry 
> about that.
> 
> The script's output is below. When I inspect the table with psql, the 
> "deleted" record is still present. And SQLAlchemy has logged the statements 
> without errors.

Your script calls the delete() under the __main__ section but then just ends, 
there's no call to commit().  Add a commit() in and the data is committed 
(assuming the zope system works, I tested here using just plain 
Session.commit() - see output below).

=== COUNTING BEFORE ============================== 

2011-08-16 19:47:32,132 INFO sqlalchemy.engine.base.Engine SELECT 
count(rolemember.id) AS count_1 
FROM rolemember
2011-08-16 19:47:32,132 INFO sqlalchemy.engine.base.Engine {}

=== FETCHING ID TO DELETE ============================== 

2011-08-16 19:47:32,133 INFO sqlalchemy.engine.base.Engine SELECT rolemember.id 
AS rolemember_id, rolemember.ctime AS rolemember_ctime, rolemember.mtime AS 
rolemember_mtime, rolemember.principal_id AS rolemember_principal_id, 
rolemember.role_id AS rolemember_role_id, rolemember.owner AS rolemember_owner, 
rolemember.editor AS rolemember_editor 
FROM rolemember ORDER BY rolemember.id 
 LIMIT %(param_1)s
2011-08-16 19:47:32,133 INFO sqlalchemy.engine.base.Engine {'param_1': 1}

=== DELETING ============================== 

2011-08-16 19:47:32,135 INFO sqlalchemy.engine.base.Engine DELETE FROM 
rolemember WHERE rolemember.id = %(id_1)s
2011-08-16 19:47:32,135 INFO sqlalchemy.engine.base.Engine {'id_1': 1L}

=== COUNTING AFTER ============================== 

2011-08-16 19:47:32,136 INFO sqlalchemy.engine.base.Engine SELECT 
count(rolemember.id) AS count_1 
FROM rolemember
2011-08-16 19:47:32,136 INFO sqlalchemy.engine.base.Engine {}

=== RESULT ============================== 

Total before: 7
Deleted id: 1
Total after: 6

Use e.g. psql to inspect db table

2011-08-16 19:47:32,137 INFO sqlalchemy.engine.base.Engine COMMIT
classics-MacBook-Pro:sqlalchemy classic$ /usr/local/pgsql/bin/psql -U scott test
psql (8.4.4)
Type "help" for help.

test=> select * from rolemember
test-> ;
 id |           ctime           | mtime | principal_id | role_id | owner | 
editor 
----+---------------------------+-------+--------------+---------+-------+--------
  2 | 2011-08-16 19:47:32.10476 |       |            1 |       2 |     1 |      
 
  3 | 2011-08-16 19:47:32.10476 |       |            2 |       3 |     1 |      
 
  4 | 2011-08-16 19:47:32.10476 |       |            2 |       2 |     1 |      
 
  5 | 2011-08-16 19:47:32.10476 |       |           98 |       3 |     1 |      
 
  6 | 2011-08-16 19:47:32.10476 |       |           98 |       2 |     1 |      
 
  7 | 2011-08-16 19:47:32.10476 |       |          101 |       3 |     1 |      
 
(6 rows)



> 
> BEGIN TEST
> 
> === COUNTING BEFORE ============================== 
> 
> 2011-08-17 01:33:41,779 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
> 2011-08-17 01:33:41,779 INFO sqlalchemy.engine.base.Engine SELECT 
> count(sample.rolemember.id) AS count_1 
> FROM sample.rolemember
> 2011-08-17 01:33:41,779 INFO sqlalchemy.engine.base.Engine {}
> 
> === FETCHING ID TO DELETE ============================== 
> 
> 2011-08-17 01:33:41,780 INFO sqlalchemy.engine.base.Engine SELECT 
> sample.rolemember.id AS sample_rolemember_id, sample.rolemember.ctime AS 
> sample_rolemember_ctime, sample.rolemember.mtime AS sample_rolemember_mtime, 
> sample.rolemember.principal_id AS sample_rolemember_principal_id, 
> sample.rolemember.role_id AS sample_rolemember_role_id, 
> sample.rolemember.owner AS sample_rolemember_owner, sample.rolemember.editor 
> AS sample_rolemember_editor 
> FROM sample.rolemember ORDER BY sample.rolemember.id 
>  LIMIT %(param_1)s OFFSET %(param_2)s
> 2011-08-17 01:33:41,780 INFO sqlalchemy.engine.base.Engine {'param_1': 1, 
> 'param_2': 0}
> 
> === DELETING ============================== 
> 
> 2011-08-17 01:33:41,781 INFO sqlalchemy.engine.base.Engine DELETE FROM 
> sample.rolemember WHERE sample.rolemember.id = %(id_1)s
> 2011-08-17 01:33:41,781 INFO sqlalchemy.engine.base.Engine {'id_1': 7L}
> 
> === COUNTING AFTER ============================== 
> 
> 2011-08-17 01:33:41,782 INFO sqlalchemy.engine.base.Engine SELECT 
> count(sample.rolemember.id) AS count_1 
> FROM sample.rolemember
> 2011-08-17 01:33:41,782 INFO sqlalchemy.engine.base.Engine {}
> 
> === RESULT ============================== 
> 
> Total before: 7
> Deleted id: 7
> Total after: 6
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/sqlalchemy/-/yIobsELwojwJ.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> <sa-test_many2many_relationship.py>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to