views:

68

answers:

3

Select all works like this:

q = session.query(products)

Now I want to add a WHERE filter, so I am trying:

q = session.query(products).filter_by(stock_count=0)

I get an error saying 'nonetype' object has no attribute 'class_manager'.

Not sure what the issue is?

Update The column seems to be mapped fine, as when I do:

q = session.query(products)

for p in q:
   print p.stock_count

It outputs the value.

But if I do:

p.stock_count = 6

I get an error also, saying: "can't set attribute"

So I can query for it, but adding the column as a filter, OR setting the value causes an error.

Strange no?

A: 

have you tried adding a .all() after your filter_by:

q = session.query(products).filter_by(stock_count=0).all()
dls
same issue......
Blankman
yeah - I verified that on my end as well - can you post your `products` class in your question?
dls
A: 

Have you tried Literal Sql? I've had the same error message but when I used literal sql it was gone.

So for your example it would be something like:

q = session.query(products).filter('stock_count==0')
Eugen
If you go with `.filter()`, you can use just `.filter(product.stock_count == 0)` instead of literals.
Daniel Kluev
A: 

filter_by() works with a keyword dictionary, you actually want to use filter(). Additionaly you can't just use stock_count (probably, you didn't show your table definition code), you have to use products.stock_count or possibly products.__class__.stock_count. So Try: q=session.query(products).filter(product.stock_count==0)

knitti