0

I've got a Flask app and I'm trying to get a SQLalchemy query using OR to return two different status like this but in one query:

        csv_list_1 = csvTable.query.filter_by(file_uuid=file_uuid).filter_by(status="Validated")

        csv_list_2 = csvTable.query.filter_by(file_uuid=file_uuid).filter_by(status="Also Validated")

I've found a couple of answers on stack overflow but trying the following:

from sqlalchemy import or_
csv_list = csvTable.query.filter_by(file_uuid=file_uuid).filter_by(or_(status="Validated", status="Also Validated"))

I get:

SyntaxError: keyword argument repeated

I'm not sure where to go from here.

1 Answer 1

2

Your column names shouldn't be keyword arguments here, it should be a boolean check like this:

csv_list = csvTable.query.filter_by(file_uuid=file_uuid)\
    .filter(or_(status == "Validated", status == "Also Validated"))
Sign up to request clarification or add additional context in comments.

2 Comments

TypeError: filter_by() takes 1 positional argument but 2 were given is the new error. I amended the link to remove the _by and just use filter csv_list = csvTable.query.filter_by(file_uuid=file_uuid)\ .filter(or_(status == "Validated", status == "Also Validated")) and it works. Thank you. Can you update your answer and I will accept.
Thanks wpercy, was knocking my head against a wall then!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.