[Python] Evaluating __[POSTCOMPILE] in a sqlalchemy based flask app

Discussão em 'Python' iniciado por Stack, Fevereiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make a flask app accept queries with multiple values using sqlalchemy but am running into some issues. Trying to debug I am running into a late evaluation issue and I am trying to view the sqlalchemy query in SQL to make sure that I am querying the Postgres db correctly. So for example I am taking multiple inputs via a normal REST api like:

    url_of_api/?var=value1,value2

    That is passed to

    import flask as f

    var = f.request.args.getlist("var")
    ap = api_endpoint.search(filters=[vars.var.in_()])


    where search is defined as:

    def search(cls, filters):
    q = Session.query(cls)
    return q.filter(*filters).all()


    So my issue is this: when I submit the query using sqlalchemy nothing is returned from my database. If I view print(Str(q.filter(*filters)) the filter part of the SQL query looks like this:

    WHERE vars.var IN (__[POSTCOMPILE_var_1])


    If I "manually" query the database like so:

    WHERE vars.var IN ('value1', 'value2')")


    I get the expected return.

    So my question is this: how do I force the evaluation of the __[POSTCOMPILE_var_1] bit that is the supplied variable values. I need to see what is being passed as a query to the database to debug but have been unable to figure out to get evaluate that. Any ideas?

    Continue reading...

Compartilhe esta Página