Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot replace BaseQuery with a Custom query_class (soft delete custom query class) #192

Open
hectorcanto opened this issue Dec 12, 2018 · 1 comment

Comments

@hectorcanto
Copy link

I want to implement a soft delete in one of my Resources. First choice would have been use Eve's soft delete but it is not possible because of #109 (#167).

I tried to implement a Flask-SQL Alchemy solution as proposed by Flask' contributor Miguel Grindberg:
https://github.com/miguelgrinberg/sqlalchemy-soft-delete/blob/master/app.py

I tried to define the query_class in several places: db.Model, the model, the Abstract clas, declarative_base... A sample of it is:

class CommonColumns(Base):
    _deleted = Column(Boolean, default=False, nullable=False)
   query_class = QueryWithSoftDelete

However, the query class ends up being flask-sqlalchemy's BaseQuery. Could it be that eve-sqlalchemy is forcing it, instead of allowing the custom query_class? Any direction on this item could be very helpful.

There is a difference that might be important for this, my models inherit from Base=sqlalchemy.ext.declarative.declarative_base() while flask-sqlalchemy typicall boilerplate models inherit from db.Model wher db=flask_sqlalchemy.SQLAlchemy().

I also tried to hardcoded the queryclass in Eve-sqlalchemy db init:
db = flask_sqlalchemy.SQLAlchemy(query_class=QueryWithSoftDelete)`` but I get the following error: sqlalchemy.exc.InvalidRequestError: Query.select_from() being called on a Query with existing criterion.```

While I would like to be able to define a custom query_class for any case scenario, I would be happy to look into allow Eve's soft delete, so I would be open to contribute provide some guidance.

Thanks for any help!

@dkellner
Copy link
Collaborator

I've no experience with using a custom query class in SQLAlchemy, sorry! Maybe the workaround @ktal90 posted can help? #109 (comment)

If not, looking into a proper support of SOFT_DELETE would be highly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants