Sqlalchemy how to clear all filters from a request

Problem.

I have a request that says so:

qr = Session.query(models.User).filter(models.User.email == email)

      

What I want to do is create a qr2 with all filters dropped, in my case this is equivalent to:

qr2 = Session.query(models.User) 

      

A good solution could be either a new query based on the old one, or without filters, or a modification of the old query.

Why would someone need it.

Imagine you have a complex query that was collecting 3 modules and 4k lines. What you get in your tiny function is a request object (instance). You don't know which models are chosen or what the actual usefulness of the request is actually. All you know is that you want to change this query so that you don't have any filters at all.

Suggestions / solutions?

+3


source to share





All Articles