mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
fix(aiohttp-session): respect UNSET sentinel (#387)
* fix(aiohttp-session): respect UNSET sentinel check if value is `UNSET` while building http request. * Cover UNSET by tests Co-authored-by: Alex Root Junior <jroot.junior@gmail.com>
This commit is contained in:
parent
85265a34cd
commit
566b7ff282
2 changed files with 4 additions and 3 deletions
|
|
@ -19,7 +19,7 @@ from aiohttp import BasicAuth, ClientSession, FormData, TCPConnector
|
||||||
|
|
||||||
from aiogram.api.methods import Request, TelegramMethod
|
from aiogram.api.methods import Request, TelegramMethod
|
||||||
|
|
||||||
from .base import BaseSession
|
from .base import BaseSession, UNSET
|
||||||
|
|
||||||
if TYPE_CHECKING: # pragma: no cover
|
if TYPE_CHECKING: # pragma: no cover
|
||||||
from ..bot import Bot
|
from ..bot import Bot
|
||||||
|
|
@ -121,7 +121,7 @@ class AiohttpSession(BaseSession):
|
||||||
def build_form_data(self, request: Request) -> FormData:
|
def build_form_data(self, request: Request) -> FormData:
|
||||||
form = FormData(quote_fields=False)
|
form = FormData(quote_fields=False)
|
||||||
for key, value in request.data.items():
|
for key, value in request.data.items():
|
||||||
if value is None:
|
if value is None or value is UNSET:
|
||||||
continue
|
continue
|
||||||
form.add_field(key, self.prepare_value(value))
|
form.add_field(key, self.prepare_value(value))
|
||||||
if request.files:
|
if request.files:
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from aresponses import ResponsesMockServer
|
||||||
from aiogram import Bot
|
from aiogram import Bot
|
||||||
from aiogram.api.client.session.aiohttp import AiohttpSession
|
from aiogram.api.client.session.aiohttp import AiohttpSession
|
||||||
from aiogram.api.methods import Request, TelegramMethod
|
from aiogram.api.methods import Request, TelegramMethod
|
||||||
from aiogram.api.types import InputFile
|
from aiogram.api.types import InputFile, UNSET
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -117,6 +117,7 @@ class TestAiohttpSession:
|
||||||
"str": "value",
|
"str": "value",
|
||||||
"int": 42,
|
"int": 42,
|
||||||
"bool": True,
|
"bool": True,
|
||||||
|
"unset": UNSET,
|
||||||
"null": None,
|
"null": None,
|
||||||
"list": ["foo"],
|
"list": ["foo"],
|
||||||
"dict": {"bar": "baz"},
|
"dict": {"bar": "baz"},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue