On 1 Sep 2013, at 22:30, Mohsen Pahlevanzadeh <[email protected]> wrote:
> Dear all,
>
> i get the following traceback for "session.query().filter(sellers.c.name ==
> 'golrang').delete('sellers')" line:
>
> ///////////////////////////////////
> Traceback (most recent call last):
> File "/home/mohsen/codes/amlak/amlak/src/test.py", line 106, in <module>
> session.query().filter(sellers.c.name == 'golrang').delete('sellers')
> File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2580,
> in delete
> self, synchronize_session)
> File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", line
> 935, in factory
> }, synchronize_session, query)
> File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", line
> 809, in _factory
> for x in lookup.keys()))))
> sqlalchemy.exc.ArgumentError: Valid strategies for session synchronization
> are 'evaluate', 'fetch', False
> ////////////////////////////////////
>
> Where's problem?
>
The 'delete' method that you are calling in the code above is Query.delete:
http://docs.sqlalchemy.org/en/rel_0_8/orm/query.html#sqlalchemy.orm.query.Query.delete
It takes 1 parameter, which tells SQLAlchemy what to do with data in the
Session after running the DELETE query. I don't know why you are passing the
string 'sellers', but it is wrong.
If you had a class mapped to the sellers table (eg. called Seller), your delete
statement should probably look like this:
session.query(Seller).filter(Seller.name == 'golrang').delete()
If you want to use the underlying sellers Table object, it would look something
like this:
delete_statement = sellers.delete().where(sellers.c.name == 'golrang')
session.execute(delete_statement)
Hope that helps,
Simon
PS. note the convention that Table instances tend to be lower-case names like
"sellers", whereas mapped classes tend to start with an upper case letter,
Seller. Also, mapped classes tend to be singular, because an instance of the
class represents a single Seller. If you follow this convention, it will be
more obvious when you are using the ORM-level objects and when you are using
the Core-level objects.
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.