Surprised no one has hit this one yet.

When issuing a series of deletes in a UOW, SA issues the bogus delete
statement

    DELETE child where id = [1,2,3]

instead of using IN()

Test case attached. Seems to work in Sqlite even while issuing the bogus SQL
(which is probably why a unit test didn't pick it up), but MS-SQL doesn't
like it; didn't check PG or others.

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

from sqlalchemy import *
import logging

logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

#metadata = BoundMetaData('mssql://d:[EMAIL PROTECTED]/drvtest')
metadata = BoundMetaData('sqlite:///:memory:')

entity = Table('entity', metadata,
    Column('id',              INT,  primary_key=True, nullable=False),
    Column('typ',             VARCHAR(12)),
    Column('lname',           VARCHAR(128))
    )

entityattr = Table('entityattr', metadata,
      Column('id',              INT,  primary_key=True, nullable=False),
      Column('ident',           INT, ForeignKey('entity.id'), nullable=False),
      Column('typ',             VARCHAR(12), nullable=False),
      Column('val',             VARCHAR(128))
      )

metadata.create_all()

class O(object):
    def __init__(self,**kw):
        for k,v in kw.items():
            setattr(self,k,v)
            
class Ent(O): pass
class Entattr(O): pass

mapper(Ent, entity, properties = {'props':relation(Entattr, cascade="all, delete-orphan")})
mapper(Entattr, entityattr)

S = create_session()

S.save(Ent(typ='A',lname='A',
           props = [Entattr(typ='A1', val='1'),
                    Entattr(typ='A2', val='2'),
                    Entattr(typ='A3', val='3'),
                    Entattr(typ='A4', val='4'),
                    Entattr(typ='A5', val='5'),
                    Entattr(typ='A6', val='6')
                    ]))
S.flush()
S.clear()

e = S.query(Ent).options(eagerload('props')).select()[0]

# remove some attributes
e.props = [p for p in e.props if 0 == int(p.val) % 2]

# put some back
e.props.append(Entattr(typ='A6', val='6'))
e.props.append(Entattr(typ='A7', val='7'))
e.props.append(Entattr(typ='A8', val='8'))

S.flush()    # <-- Delete issued here
S.clear()

e = S.query(Ent).options(eagerload('props')).select()[0]
assert 6 == len(e.props)

metadata.drop_all()

Reply via email to