On Mar 16, 2011, at 3:38 PM, writeson wrote:

> Hi all,
> 
> This is probably a simple problem, but so far I haven't figured out
> how to resolve it. I've got some SqlAlchemy tables and am trying to
> change an attribute of a SqlAlchemy object returned from a query.
> However, when I change the attribute value, no SQL update statement is
> generated by the session.commit() that follows. Here's my table
> definitions:
> 
> 
> class CoverBatchStackItem(Base):
>    __tablename__ = "cover_batch_stack_items"
>    cover_batch_id = Col(Int, FK("cover_batch_stacks.cover_batch_id"),
>                         primary_key=True)
>    stack_number   = Col(Int, FK("cover_batch_stacks.stack_number"),
>                       primary_key=True)
>    order_id       = Col(Int, FK("order_header.order_id"),
> primary_key=True)
>    qty            = Col(Int)
> 
> And here is a sample of my Python code to update the 'qty' attribute:
> 
> # session is passed in by the caller of this code, along with qty
> item = session.query(CoverBatchStackItem) \
>       .filter((CoverBatchStackItem.cover_batch_id==cover_batch_id)
> and
>               (CoverBatchStackItem.order_id==order_id)) \
>       .first()
> item.qty = 10
> session.commit()
> 
> I don't know why, but the change to the 'qty' attribute is not being
> detected, and therefore not generating an SQL update statement to
> persist the change to the database.
> 
> Any help or suggestions would be greatly appreciated!
> Thanks in advance,

there's nothing obviously wrong with the above other than the unusual naming 
scheme of "Col", "Int", and "FK".     Two steps to take are to assert that the 
object is dirty, "assert item in session.dirty", and the attribute has a 
change,  "from sqlalchemy.orm import attributes; assert 
attributes.get_history(item, 'qty').has_changes()", before flush() or commit() 
is called.




> Doug
> 
> -- 
> 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.
> 

-- 
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