6

I'm getting a sytax error for the following statement, the problem section being (Player.name == data["name"]) | (Player.account == data["account"])):

player_from_db = db.session.execute(select(Player).where((Player.name == data["name"]) | (Player.account == data["account"]))).scalar()

This is the error:

Expected type 'Union[ColumnElement[bool], _HasClauseElement, SQLCoreOperations[bool], ExpressionElementRole[bool], () -> ColumnElement[bool], LambdaElement]', got 'Union[bool, int]' instead 

But the clause clearly has two bool expressions. Help appreciated!

am1234
  • 93
  • 1
  • 9
  • 1
    Not sure here, but have you tried replacing the pipe with an or_? https://docs.sqlalchemy.org/en/20/core/operators.html#:~:text=Operators.__or__()%20(Python%20%E2%80%9C%7C%E2%80%9D%20operator)%3A – Ben Mar 27 '23 at 18:52
  • 1
    Please try with or_() instead of pipe https://docs.sqlalchemy.org/en/20/core/sqlelement.html#sqlalchemy.sql.expression.or_ – Chandhan Narayanareddy Apr 12 '23 at 08:51

0 Answers0