Skip to content

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

@hectorcanto

Description

@hectorcanto

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions