The following issues were found
docs_src/response_model/tutorial003.py
8 issues
Line: 3
Column: 1
from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
class UserIn(BaseModel):
Reported by Pylint.
Line: 4
Column: 1
from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
class UserIn(BaseModel):
Reported by Pylint.
Line: 1
Column: 1
from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
class UserIn(BaseModel):
Reported by Pylint.
Line: 9
Column: 1
app = FastAPI()
class UserIn(BaseModel):
username: str
password: str
email: EmailStr
full_name: Optional[str] = None
Reported by Pylint.
Line: 9
Column: 1
app = FastAPI()
class UserIn(BaseModel):
username: str
password: str
email: EmailStr
full_name: Optional[str] = None
Reported by Pylint.
Line: 16
Column: 1
full_name: Optional[str] = None
class UserOut(BaseModel):
username: str
email: EmailStr
full_name: Optional[str] = None
Reported by Pylint.
Line: 16
Column: 1
full_name: Optional[str] = None
class UserOut(BaseModel):
username: str
email: EmailStr
full_name: Optional[str] = None
Reported by Pylint.
Line: 23
Column: 1
@app.post("/user/", response_model=UserOut)
async def create_user(user: UserIn):
return user
Reported by Pylint.
docs_src/body_nested_models/tutorial005.py
8 issues
Line: 3
Column: 1
from typing import Optional, Set
from fastapi import FastAPI
from pydantic import BaseModel, HttpUrl
app = FastAPI()
class Image(BaseModel):
Reported by Pylint.
Line: 4
Column: 1
from typing import Optional, Set
from fastapi import FastAPI
from pydantic import BaseModel, HttpUrl
app = FastAPI()
class Image(BaseModel):
Reported by Pylint.
Line: 1
Column: 1
from typing import Optional, Set
from fastapi import FastAPI
from pydantic import BaseModel, HttpUrl
app = FastAPI()
class Image(BaseModel):
Reported by Pylint.
Line: 9
Column: 1
app = FastAPI()
class Image(BaseModel):
url: HttpUrl
name: str
class Item(BaseModel):
Reported by Pylint.
Line: 9
Column: 1
app = FastAPI()
class Image(BaseModel):
url: HttpUrl
name: str
class Item(BaseModel):
Reported by Pylint.
Line: 14
Column: 1
name: str
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
tags: Set[str] = set()
Reported by Pylint.
Line: 14
Column: 1
name: str
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
tags: Set[str] = set()
Reported by Pylint.
Line: 24
Column: 1
@app.put("/items/{item_id}")
async def update_item(item_id: int, item: Item):
results = {"item_id": item_id, "item": item}
return results
Reported by Pylint.
docs_src/background_tasks/tutorial002.py
8 issues
Line: 3
Column: 1
from typing import Optional
from fastapi import BackgroundTasks, Depends, FastAPI
app = FastAPI()
def write_log(message: str):
with open("log.txt", mode="a") as log:
Reported by Pylint.
Line: 22
Column: 52
@app.post("/send-notification/{email}")
async def send_notification(
email: str, background_tasks: BackgroundTasks, q: str = Depends(get_query)
):
message = f"message to {email}\n"
background_tasks.add_task(write_log, message)
return {"message": "Message sent"}
Reported by Pylint.
Line: 1
Column: 1
from typing import Optional
from fastapi import BackgroundTasks, Depends, FastAPI
app = FastAPI()
def write_log(message: str):
with open("log.txt", mode="a") as log:
Reported by Pylint.
Line: 8
Column: 1
app = FastAPI()
def write_log(message: str):
with open("log.txt", mode="a") as log:
log.write(message)
def get_query(background_tasks: BackgroundTasks, q: Optional[str] = None):
Reported by Pylint.
Line: 13
Column: 1
log.write(message)
def get_query(background_tasks: BackgroundTasks, q: Optional[str] = None):
if q:
message = f"found query: {q}\n"
background_tasks.add_task(write_log, message)
return q
Reported by Pylint.
Line: 13
Column: 1
log.write(message)
def get_query(background_tasks: BackgroundTasks, q: Optional[str] = None):
if q:
message = f"found query: {q}\n"
background_tasks.add_task(write_log, message)
return q
Reported by Pylint.
Line: 21
Column: 1
@app.post("/send-notification/{email}")
async def send_notification(
email: str, background_tasks: BackgroundTasks, q: str = Depends(get_query)
):
message = f"message to {email}\n"
background_tasks.add_task(write_log, message)
return {"message": "Message sent"}
Reported by Pylint.
Line: 21
Column: 1
@app.post("/send-notification/{email}")
async def send_notification(
email: str, background_tasks: BackgroundTasks, q: str = Depends(get_query)
):
message = f"message to {email}\n"
background_tasks.add_task(write_log, message)
return {"message": "Message sent"}
Reported by Pylint.
docs_src/body_nested_models/tutorial004.py
8 issues
Line: 3
Column: 1
from typing import Optional, Set
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Image(BaseModel):
Reported by Pylint.
Line: 4
Column: 1
from typing import Optional, Set
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Image(BaseModel):
Reported by Pylint.
Line: 1
Column: 1
from typing import Optional, Set
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Image(BaseModel):
Reported by Pylint.
Line: 9
Column: 1
app = FastAPI()
class Image(BaseModel):
url: str
name: str
class Item(BaseModel):
Reported by Pylint.
Line: 9
Column: 1
app = FastAPI()
class Image(BaseModel):
url: str
name: str
class Item(BaseModel):
Reported by Pylint.
Line: 14
Column: 1
name: str
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
tags: Set[str] = []
Reported by Pylint.
Line: 14
Column: 1
name: str
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
tags: Set[str] = []
Reported by Pylint.
Line: 24
Column: 1
@app.put("/items/{item_id}")
async def update_item(item_id: int, item: Item):
results = {"item_id": item_id, "item": item}
return results
Reported by Pylint.
tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py
8 issues
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.path_operation_configuration.tutorial006 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.path_operation_configuration.tutorial006 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 56
Column: 1
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 58
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
@pytest.mark.parametrize(
"path,expected_status,expected_response",
Reported by Bandit.
Line: 59
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
@pytest.mark.parametrize(
"path,expected_status,expected_response",
[
Reported by Bandit.
Line: 68
Column: 1
("/items/", 200, [{"name": "Foo", "price": 42}]),
("/users/", 200, [{"username": "johndoe"}]),
("/elements/", 200, [{"item_id": "Foo"}]),
],
)
def test_query_params_str_validations(path, expected_status, expected_response):
response = client.get(path)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Pylint.
Line: 72
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test_query_params_str_validations(path, expected_status, expected_response):
response = client.get(path)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
Line: 73
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_query_params_str_validations(path, expected_status, expected_response):
response = client.get(path)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
tests/test_tutorial/test_body_multiple_params/test_tutorial001.py
8 issues
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.body_multiple_params.tutorial001 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.body_multiple_params.tutorial001 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 104
Column: 1
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 106
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
item_id_not_int = {
"detail": [
Reported by Bandit.
Line: 107
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
item_id_not_int = {
"detail": [
{
Reported by Bandit.
Line: 142
Column: 1
("/items/5?q=bar", None, 200, {"item_id": 5, "q": "bar"}),
("/items/5", None, 200, {"item_id": 5}),
("/items/foo", None, 422, item_id_not_int),
],
)
def test_post_body(path, body, expected_status, expected_response):
response = client.put(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Pylint.
Line: 146
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test_post_body(path, body, expected_status, expected_response):
response = client.put(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
Line: 147
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_post_body(path, body, expected_status, expected_response):
response = client.put(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
tests/test_tutorial/test_body_multiple_params/test_tutorial003.py
8 issues
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.body_multiple_params.tutorial003 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.body_multiple_params.tutorial003 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
Reported by Pylint.
Line: 115
Column: 1
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 117
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
# Test required and embedded body parameters with no bodies sent
@pytest.mark.parametrize(
Reported by Bandit.
Line: 118
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
# Test required and embedded body parameters with no bodies sent
@pytest.mark.parametrize(
"path,body,expected_status,expected_response",
Reported by Bandit.
Line: 189
Column: 1
"loc": ["body", "importance"],
"msg": "field required",
"type": "value_error.missing",
},
]
},
),
],
)
Reported by Pylint.
Line: 197
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test_post_body(path, body, expected_status, expected_response):
response = client.put(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
Line: 198
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_post_body(path, body, expected_status, expected_response):
response = client.put(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
tests/test_tutorial/test_body_fields/test_tutorial001.py
8 issues
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.body_fields.tutorial001 import app
client = TestClient(app)
openapi_schema = {
Reported by Pylint.
Line: 1
Column: 1
import pytest
from fastapi.testclient import TestClient
from docs_src.body_fields.tutorial001 import app
client = TestClient(app)
openapi_schema = {
Reported by Pylint.
Line: 112
Column: 1
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 114
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
price_not_greater = {
"detail": [
Reported by Bandit.
Line: 115
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
price_not_greater = {
"detail": [
{
Reported by Bandit.
Line: 164
Column: 1
},
),
("/items/5", {"item": {"name": "Foo", "price": -3.0}}, 422, price_not_greater),
],
)
def test(path, body, expected_status, expected_response):
response = client.put(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Pylint.
Line: 168
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test(path, body, expected_status, expected_response):
response = client.put(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
Line: 169
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test(path, body, expected_status, expected_response):
response = client.put(path, json=body)
assert response.status_code == expected_status
assert response.json() == expected_response
Reported by Bandit.
tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py
8 issues
Line: 1
Column: 1
from fastapi.testclient import TestClient
from docs_src.path_operation_configuration.tutorial005 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
Reported by Pylint.
Line: 34
Column: 1
},
},
"summary": "Create an item",
"description": "Create an item with all the information:\n\n- **name**: each item must have a name\n- **description**: a long description\n- **price**: required\n- **tax**: if the item doesn't have tax, you can omit this\n- **tags**: a set of unique tag strings for this item",
"operationId": "create_item_items__post",
"requestBody": {
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/Item"}
Reported by Pylint.
Line: 97
Column: 1
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 99
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
Reported by Bandit.
Line: 100
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
Reported by Bandit.
Line: 103
Column: 1
assert response.json() == openapi_schema
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
assert response.json() == {
"name": "Foo",
"price": 42,
Reported by Pylint.
Line: 105
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
assert response.json() == {
"name": "Foo",
"price": 42,
"description": None,
"tax": None,
Reported by Bandit.
Line: 106
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_query_params_str_validations():
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
assert response.json() == {
"name": "Foo",
"price": 42,
"description": None,
"tax": None,
"tags": [],
Reported by Bandit.
tests/test_tutorial/test_metadata/test_tutorial001.py
8 issues
Line: 1
Column: 1
from fastapi.testclient import TestClient
from docs_src.metadata.tutorial001 import app
client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {
Reported by Pylint.
Line: 11
Column: 1
"openapi": "3.0.2",
"info": {
"title": "ChimichangApp",
"description": "\nChimichangApp API helps you do awesome stuff. 🚀\n\n## Items\n\nYou can **read items**.\n\n## Users\n\nYou will be able to:\n\n* **Create users** (_not implemented_).\n* **Read users** (_not implemented_).\n",
"termsOfService": "http://example.com/terms/",
"contact": {
"name": "Deadpoolio the Amazing",
"url": "http://x-force.example.com/contact/",
"email": "dp@x-force.example.com",
Reported by Pylint.
Line: 41
Column: 1
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
Reported by Pylint.
Line: 43
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_items():
response = client.get("/items/")
Reported by Bandit.
Line: 44
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_items():
response = client.get("/items/")
assert response.status_code == 200, response.text
Reported by Bandit.
Line: 47
Column: 1
assert response.json() == openapi_schema
def test_items():
response = client.get("/items/")
assert response.status_code == 200, response.text
assert response.json() == [{"name": "Katana"}]
Reported by Pylint.
Line: 49
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_items():
response = client.get("/items/")
assert response.status_code == 200, response.text
assert response.json() == [{"name": "Katana"}]
Reported by Bandit.
Line: 50
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_items():
response = client.get("/items/")
assert response.status_code == 200, response.text
assert response.json() == [{"name": "Katana"}]
Reported by Bandit.