I created a database using PostgreSQL with SQLAlchemy and FastAPI. I set up JWT authentication for a route. But when I try it, I get the following error:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'Depends'
[SQL: SELECT "tbl_stu_usr-my_profile-my_skill".id AS "tbl_stu_usr-my_profile-my_skill_id", "tbl_stu_usr-my_profile-my_skill".user_id AS "tbl_stu_usr-my_profile-my_skill_user_id", "tbl_stu_usr-my_profile-my_skill".proficiency AS "tbl_stu_usr-my_profile-my_skill_proficiency", "tbl_stu_usr-my_profile-my_skill".title AS "tbl_stu_usr-my_profile-my_skill_title", "tbl_stu_usr-my_profile-my_skill".experience AS "tbl_stu_usr-my_profile-my_skill_experience", "tbl_stu_usr-my_profile-my_skill".last_used AS "tbl_stu_usr-my_profile-my_skill_last_used", "tbl_stu_usr-my_profile-my_skill".description AS "tbl_stu_usr-my_profile-my_skill_description"
FROM "tbl_stu_usr-my_profile-my_skill"
WHERE "tbl_stu_usr-my_profile-my_skill".user_id = %(user_id_1)s]
[parameters: {'user_id_1': Depends(get_current_user)}]
(Background on this error at: https://sqlalche.me/e/14/f405)
I tried this:
from src.app.common.models.models import My_Skill, Notification_My_Activity
from src.config.common.auth import oauth2
from fastapi import APIRouter, Depends, status, Response, HTTPException, File, UploadFile
def get_all_user_skill(db: Session, current_user: schemas.UserAuth = Depends(oauth2.get_current_user)):
try:
education_user_specific = db.query(My_Skill).filter(My_Skill.user_id == current_user).all()
if education_user_specific:
return education_user_specific
if not education_user_specific:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
detail=f"There is nothing to show")
except SQLAlchemyError:
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=properties.error_message)