I have a class with a attribute.
I'm trying to check if the user pass the correct attribute though the API, however my statement always return true even the data didn't match the first condition. I even try to switch the condition and it still return true in the first condition
Is there a basic things I miss or was intended?
edit 1: switch the condition to prevent confusion, the function will always return 'wrong input' no matter what input even with empty string
My code:
import uvicorn
from pydantic import BaseModel
from fastapi import FastAPI, HTTPException
class Test_var(BaseModel):
test_attr: str
app = FastAPI()
@app.post("/test_request/")
async def root(test_var: Test_var):
data_validation(test_var)
def data_validation(test_var):
if 'M' and 'G' not in test_var.test_attr:
raise HTTPException( status_code = 422, detail = "wrong input")
elif 'M' or 'G' in test_var.test_attr:
print(test_var.test_attr)
raise HTTPException(status_code = 422, detail = "correct input")