Query.delete does not work with a string filter

Issue #1242 resolved
Former user created an issue

Deleting objects using ORM query with a .filter('something') does not delete any rows.

A test program demonstrating the problem is attached.

Comments (6)

  1. Mike Bayer repo owner

    here's a patch if someone wants to create a unit test for us to test/orm/query UpdateDeleteTest, which tests both delete() and update()

    Index: lib/sqlalchemy/orm/query.py
    ===================================================================
    --- lib/sqlalchemy/orm/query.py (revision 5459)
    +++ lib/sqlalchemy/orm/query.py (working copy)
    @@ -1371,11 +1371,11 @@
             if synchronize_session == 'fetch':
                 #TODO: use RETURNING when available
                 select_stmt = context.statement.with_only_columns(primary_table.primary_key)
    -            matched_rows = session.execute(select_stmt).fetchall()
    +            matched_rows = session.execute(select_stmt, params=self._params).fetchall()
    
             if self._autoflush:
                 session._autoflush()
    -        result = session.execute(delete_stmt)
    +        result = session.execute(delete_stmt, params=self._params)
    
             if synchronize_session == 'evaluate':
                 target_cls = self._mapper_zero().class_
    @@ -1456,11 +1456,11 @@
    
             if synchronize_session == 'expire':
                 select_stmt = context.statement.with_only_columns(primary_table.primary_key)
    -            matched_rows = session.execute(select_stmt).fetchall()
    +            matched_rows = session.execute(select_stmt, params=self._params).fetchall()
    
             if self._autoflush:
                 session._autoflush()
    -        result = session.execute(update_stmt)
    +        result = session.execute(update_stmt, params=self._params)
    
             if synchronize_session == 'evaluate':
                 target_cls = self._mapper_zero().class_
    
  2. Log in to comment