-1

i implemented in my flask api rest app, this code to get the use from id into database:

@blp.route("/v0/user/<int:id>")
class User(MethodView):
    @blp.response(200, UserSchema)
    def get(self, id):
        user = UserModel.query.get_or_404(id)
        return user

now i want to implement the same logic to get only user passing uuid_user that is a value of model user and is in my database, using this code:

@blp.route("/v0/user_uuid/<string:uuid_user>")
class UserUuid(MethodView):
    @blp.response(200, UserSchema)
    def get(self,uuid_user):
        user = UserModel.query.filter(uuid_user).all()
        return user

but i receive this error when i call the endpoint of this api:

File "/app/resources/user.py", line 150, in get
    user = UserModel.query.filter(uuid_user).all()
  File "<string>", line 2, in filter
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/base.py", line 248, in _generative"

Any help how to fix it? Where is the error? Thanks

dev_
  • 395
  • 1
  • 3
  • 16
  • Usually, `filter` is passed something that compares values in the database with some other criterion, so for example `UseModelr.query.filter(UserModel.id == uuid_user).all()`. That said I can't easily reproduce the specific error that you are reporting - is that the _complete_ traceback? – snakecharmerb Mar 11 '23 at 17:40

1 Answers1

0

thanks for your replay. I have fixed the issue in this way:

@blp.route("/v0/user_uuid/<string:uuid_user>")
class UserUuid(MethodView):
@blp.response(200, UserSchema)
def get(self,uuid_user):
    user = UserModel.query.filter_by(uuid_user = uuid_user).first_or_404()
    return user
dev_
  • 395
  • 1
  • 3
  • 16