-
Notifications
You must be signed in to change notification settings - Fork 153
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
TypeError: @validator(..., each_item=True)
cannot be applied to fields with a schema of json-or-python
#98
Comments
Hello! The same problem here when updating to |
I get this error simply by importing
|
For me I could fix the issue by downgrading to:
Since this repo has not seen any movement in two years, this might be the only solution available until a fork appears. |
Hey, |
I get the very same error. thanks for the workaround, which does the job for me for the moment. |
@georg-mayer If that can help, this PR shows how I migrated a project of mine from |
thx for solution! |
Same issue |
Any good replacement for fastapi-jwt-auth? |
No, the last time, I used https://github.com/GlitchCorp/fastapi-another-jwt-auth as an alternative but seems like the maintainer abandoned it. |
To re-iterate #98 (comment): I've had good success using https://github.com/k4black/fastapi-jwt as a replacement library. Some changes in the codebase were required, but not much. |
Is there any update regarding this to issue in order to make it work with pydantic==2..? |
You will need to change Here is my entire file from datetime import timedelta
from typing import Optional, Union, Sequence, List
from pydantic import (
BaseModel,
validator,
StrictBool,
StrictInt,
StrictStr
)
class LoadConfig(BaseModel):
authjwt_token_location: Optional[List[StrictStr]] = ['headers']
authjwt_secret_key: Optional[StrictStr] = None
authjwt_public_key: Optional[StrictStr] = None
authjwt_private_key: Optional[StrictStr] = None
authjwt_algorithm: Optional[StrictStr] = "HS256"
authjwt_decode_algorithms: Optional[List[StrictStr]] = None
authjwt_decode_leeway: Optional[Union[StrictInt,timedelta]] = 0
authjwt_encode_issuer: Optional[StrictStr] = None
authjwt_decode_issuer: Optional[StrictStr] = None
authjwt_decode_audience: Optional[Union[StrictStr,Sequence[StrictStr]]] = None
authjwt_denylist_enabled: Optional[StrictBool] = False
authjwt_denylist_token_checks: Optional[List[StrictStr]] = ['access','refresh']
authjwt_header_name: Optional[StrictStr] = "Authorization"
authjwt_header_type: Optional[StrictStr] = "Bearer"
authjwt_access_token_expires: Optional[Union[StrictBool,StrictInt,timedelta]] = timedelta(minutes=15)
authjwt_refresh_token_expires: Optional[Union[StrictBool,StrictInt,timedelta]] = timedelta(days=30)
# # option for create cookies
authjwt_access_cookie_key: Optional[StrictStr] = "access_token_cookie"
authjwt_refresh_cookie_key: Optional[StrictStr] = "refresh_token_cookie"
authjwt_access_cookie_path: Optional[StrictStr] = "/"
authjwt_refresh_cookie_path: Optional[StrictStr] = "/"
authjwt_cookie_max_age: Optional[StrictInt] = None
authjwt_cookie_domain: Optional[StrictStr] = None
authjwt_cookie_secure: Optional[StrictBool] = False
authjwt_cookie_samesite: Optional[StrictStr] = None
# # option for double submit csrf protection
authjwt_cookie_csrf_protect: Optional[StrictBool] = True
authjwt_access_csrf_cookie_key: Optional[StrictStr] = "csrf_access_token"
authjwt_refresh_csrf_cookie_key: Optional[StrictStr] = "csrf_refresh_token"
authjwt_access_csrf_cookie_path: Optional[StrictStr] = "/"
authjwt_refresh_csrf_cookie_path: Optional[StrictStr] = "/"
authjwt_access_csrf_header_name: Optional[StrictStr] = "X-CSRF-Token"
authjwt_refresh_csrf_header_name: Optional[StrictStr] = "X-CSRF-Token"
authjwt_csrf_methods: Optional[List[StrictStr]] = ['POST','PUT','PATCH','DELETE']
@validator('authjwt_access_token_expires')
def validate_access_token_expires(cls, v):
if v is True:
raise ValueError("The 'authjwt_access_token_expires' only accept value False (bool)")
return v
@validator('authjwt_refresh_token_expires')
def validate_refresh_token_expires(cls, v):
if v is True:
raise ValueError("The 'authjwt_refresh_token_expires' only accept value False (bool)")
return v
@validator('authjwt_denylist_token_checks', each_item=True)
def validate_denylist_token_checks(cls, v):
if v not in ['access','refresh']:
raise ValueError("The 'authjwt_denylist_token_checks' must be between 'access' or 'refresh'")
return v
@validator('authjwt_token_location', each_item=True)
def validate_token_location(cls, v):
if v not in ['headers','cookies']:
raise ValueError("The 'authjwt_token_location' must be between 'headers' or 'cookies'")
return v
@validator('authjwt_cookie_samesite')
def validate_cookie_samesite(cls, v):
if v not in ['strict','lax','none']:
raise ValueError("The 'authjwt_cookie_samesite' must be between 'strict', 'lax', 'none'")
return v
@validator('authjwt_csrf_methods', each_item=True)
def validate_csrf_methods(cls, v):
if v.upper() not in ["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH"]:
raise ValueError("The 'authjwt_csrf_methods' must be between http request methods")
return v.upper()
class Config:
str_min_length = 1
str_strip_whitespace = True |
Using it from this fork resolved the issue for me. I just bumped the pydantic version to 2.7.0 without any application errors. |
I have problem belong TypeError: |
@jahongir7797 Use the mentioned fork in the above comment. That resolved it for me. |
Hi, I'm getting this error when running the example https://indominusbyte.github.io/fastapi-jwt-auth/usage/basic/
Please help. Thank you!
The text was updated successfully, but these errors were encountered: