session.delete() only works with instances which are already part of that 
session. Here's an example:

  ddd = session.query(SellersTable).filter_by(name_type=1).one()
  session.delete(ddd)

This will SELECT the row from the database first, then perform the DELETE using 
the object's primary key. If you want to avoid the SELECT, you can use the 
Query.delete() method, something like this:

  session.query(SellersTable).filter_by(name_type=1).delete()

http://docs.sqlalchemy.org/en/rel_0_8/orm/query.html#sqlalchemy.orm.query.Query.delete

Hope that helps,

Simon


On 27 Aug 2013, at 18:28, Mohsen Pahlevanzadeh <m.pahlevanza...@gmail.com> 
wrote:

> My ddd object :
> ddd = SellersTable(dict([('name_type',1) ]))
> dbObj.deleteRecord(ddd);
> 
> SellersTable is a class table that contains __tablename__ and fileds name. I 
> pass a dictionary that consist of my field and its value.
> 
> I chekced, it stored in DB.
> 
> 
> On Tuesday, August 27, 2013 2:47:46 AM UTC+4:30, Mohsen Pahlevanzadeh wrote:
> Dear all,
> 
> 
> i have the following delete record function:
> 
>     def deleteRecord(self,tableObj):
>         self.session.delete(tableObj);
>         self.session.commit();
> 
> 
> When i call the abobe function, before commit(), i get the following 
> traceback:
> 
> Traceback (most recent call last):
>   File "./main.py", line 66, in <module>
>     main()
>   File "./main.py", line 53, in main
>     dbObj.deleteRecord(ddd);
>   File "/home/mohsen/projects/amlak/dbabslayer/dbabslayer.py", line 86, in 
> deleteRecord
>     self.session.delete(tableObj);
>   File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 
> 1437, in delete
>     orm_util.state_str(state))
> sqlalchemy.exc.InvalidRequestError: Instance '<SellersTable at 0x994a90c>' is 
> not persisted
> 
> dbabslayer class have a set of function such as deleteRecord, addRecord, 
> createEngine, createSession and so on.
> SellersTable is class name of sellers table.
> 
> Where's Problem?
> 
> 
> -- 
> 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/groups/opt_out.

-- 
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/groups/opt_out.

Reply via email to