Fantastic, thanks!

On Tuesday, April 14, 2015 at 4:00:01 PM UTC+1, Michael Bayer wrote:
>
>  
>
> On 4/14/15 6:38 AM, Steven Winfield wrote:
>  
>  Hi, 
>
>  I think I've found a bug triggered by bulk deletes that use the 
> (default) "evaluate" strategy.
>  
>
> a bug is created at 
> https://bitbucket.org/zzzeek/sqlalchemy/issue/3365/evaluator-cant-locate-orm-entity-when
>   
> and for now you need to compare using the columns, not the relationship, 
> e.g. Child._id_parent == parent.id, if you want to use evaluate there.
>
>
>  
>  For example: 
>
>  from sqlalchemy import Column, Integer, Text, ForeignKey, create_engine
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.orm import sessionmaker, relationship
>
>  Base = declarative_base()
>
>  class Parent(Base):
>     __tablename__ = "parent"
>     id = Column(Integer, primary_key=True)
>
>  class Child(Base):
>     __tablename__ = "child"
>     _id_parent = Column("id_parent", Integer, ForeignKey(Parent.id), 
> primary_key=True)
>     name = Column(Text, primary_key=True)
>     parent = relationship(Parent)
>
>  engine = create_engine('sqlite://')
> Base.metadata.create_all(engine)
> Session = sessionmaker(bind=engine)
> session = Session()
> session.bind.echo = True
>
>  # Make a parent
> p = Parent(id=1)
> session.add(p)
> session.commit()
>
>  # Add a child
> c = Child(name="foo", parent=p)
> session.add(c)
> session.commit()
> # c is still in the session
>
>  session.query(Child).filter(Child.parent == p).delete("evaluate")
>  
>  ...give the following traceback:
>
>  File user!winfis!test_bed.py, line 34, in : 
> session.query(Child).filter(Child.parent == p).delete("evaluate") 
> File 
> R:\sw\external\20150407-0\python27\lib\site-packages\sqlalchemy-0.9.7-py2.7-win32.egg\sqlalchemy\orm\query.py,
>  
> line 2670, in delete : delete_op.exec_() 
> File 
> R:\sw\external\20150407-0\python27\lib\site-packages\sqlalchemy-0.9.7-py2.7-win32.egg\sqlalchemy\orm\persistence.py,
>  
> line 896, in exec_ : self._do_pre_synchronize() 
> File 
> R:\sw\external\20150407-0\python27\lib\site-packages\sqlalchemy-0.9.7-py2.7-win32.egg\sqlalchemy\orm\persistence.py,
>  
> line 958, in _do_pre_synchronize : eval_condition(obj)] 
> File 
> R:\sw\external\20150407-0\python27\lib\site-packages\sqlalchemy-0.9.7-py2.7-win32.egg\sqlalchemy\orm\evaluator.py,
>  
> line 116, in evaluate : right_val = eval_right(obj) 
> File 
> R:\sw\external\20150407-0\python27\lib\site-packages\sqlalchemy-0.9.7-py2.7-win32.egg\sqlalchemy\orm\evaluator.py,
>  
> line 72, in : return lambda obj: get_corresponding_attr(obj) 
> AttributeError: 'Child' object has no attribute 'id_parent'
>
>
>  ...because the attribute lookup on Child is attempted using the column 
> name, rather than the attribute name. The actual delete action works fine 
> when I switch the strategy to False or "fetch", or if there are no Child 
> objects in the session (so no evaluation is invoked).
>
>
>  As you can see, this is v0.9.7, but I've not seen anything relevant in 
> the changelog since then. 
>
>  Cheers,
> Steve.
>  -- 
> 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+...@googlegroups.com <javascript:>.
> To post to this group, send email to sqlal...@googlegroups.com 
> <javascript:>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>
>  

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to