Skip to content

If some parameter is popped from data during validation it will be popped from actual data it seems #12977

Closed as not planned
@GoiDcl

Description

@GoiDcl

In my validate function i have this code:

try:
    brc_type: int = data.get('broadcast_type')
    parameters: dict = data.pop('parameters')
except KeyError as e:
    raise serializers.ValidationError(
        f'Mandatory key is missing: {e}'
    )

I try to test if two staff roles can create an order like this:

def test_create_valid_adorder_staff(
    self,
    admin_client,
    manager_client,
    admin_user,
    manager_user,
    nomenclature,
    playlist_1
):
    today = f'{dt.today().date()} 09:00:00'
    tomorrow = f'{dt.today().date() + td(days=1)} 20:00:00'
    adorder_count = AdOrder.objects.count()
    valid_data = [
        [{
            'name': 'test',
            'broadcast_interval': {'lower': today, 'upper': tomorrow},
            'clients': [str(nomenclature.id)],
            'playlist': str(playlist_1.id),
            'broadcast_type': 0,
            'parameters': {'times_in_hour': 4}
        }],
         [{
            'name': 'test',
            'broadcast_interval': {'lower': today, 'upper': tomorrow},
            'clients': [str(nomenclature.id)],
            'playlist': str(playlist_1.id),
            'broadcast_type': 1,
            'parameters': {'times_in_hour': 4, 'timedelta': '01:00:00'}
        }],
        ...
    ]
    clients = {admin_client: admin_user, manager_client: manager_user}
    for combo in product(clients, valid_data):
        response = combo[0].post(
            self.ad_list_url,
            data=combo[1],
            format='json'
        )
    ...

So when the second client starts to post data, the data is missing parameters
I did this to be sure:

assert response.status_code == HTTPStatus.OK, 'response status code is not 200 OK for data: {combo[1]}, client:
 {clients[combo[0].full_name]}'

This shows me the following

E           AssertionError: response status code is not 200 OK for data: [{'name': 'test', 'broadcast_interval': {'lower': '2024-11-19 09:00:00',
 'upper': '2024-11-20 20:00:00'}, 'clients': ['02cf2a53-ca2c-4fe4-a5ef-fd48d9cc9b49'], 'playlist': '1d2311dc-03f1-45db-b5fd-
418e6e977b0b', 'broadcast_type': 0, 'parameters': {}}], client: 'manager manager'

As you can see parameters are empty. That is the same as if parameters would missing in my Postman after sending request

pip list output:

Package                       Version
----------------------------- -----------
amqp                          5.2.0
argon2-cffi                   23.1.0
argon2-cffi-bindings          21.2.0
asgiref                       3.8.1
async-timeout                 4.0.3
attrs                         23.2.0
billiard                      4.2.0
celery                        5.4.0
celery-singleton              0.3.1
certifi                       2024.2.2
cffi                          1.16.0
channels                      4.1.0
channels-redis                4.2.0
charset-normalizer            3.3.2
click                         8.1.7
click-didyoumean              0.3.1
click-plugins                 1.1.1
click-repl                    0.3.0
clickhouse-connect            0.7.4
clickhouse-driver             0.2.8
colorama                      0.4.6
cryptography                  42.0.5
defusedxml                    0.8.0rc2
Django                        5.0.3
django-clickhouse-backend     1.3
django-cors-headers           4.3.1
django-debug-toolbar          4.3.0
django-filter                 24.2
django-minio-backend          3.6.0
django-minio-storage          0.5.7
django-phonenumber-field      7.3.0
django-sqlprint-middleware    0.1.4
django-templated-mail         1.1.1
djangorestframework           3.15.1
djangorestframework-simplejwt 5.3.1
djoser                        2.2.2
drf-yasg                      1.21.7
flake8                        7.0.0
flake8-commas                 2.1.0
flake8-docstrings             1.7.0
flake8-multiline-containers   0.0.19
flake8-polyfill               1.0.2
flake8-quotes                 3.4.0
flake8-variables-names        0.0.6
gunicorn                      22.0.0
idna                          3.6
inflection                    0.5.1
iniconfig                     2.0.0
isort                         5.13.2
kombu                         5.4.0
lz4                           4.3.3
mccabe                        0.7.0
minio                         7.2.5
msgpack                       1.0.8
oauthlib                      3.2.2
packaging                     24.0
pep8-naming                   0.13.3
phonenumberslite              8.13.33
pip                           24.0
pluggy                        1.5.0
prompt-toolkit                3.0.43
psycopg                       3.1.18
psycopg-binary                3.1.18
pycodestyle                   2.11.1
pycparser                     2.22
pycryptodome                  3.20.0
pydocstyle                    6.3.0
pyflakes                      3.2.0
Pygments                      2.17.2
pygments-pprint-sql           0.1.0
PyJWT                         2.8.0
pytest                        8.3.3
pytest-django                 4.9.0
python-dateutil               2.9.0.post0
python-dotenv                 1.0.1
python3-openid                3.2.0
pytz                          2024.1
PyYAML                        6.0.1
redis                         5.2.0
requests                      2.31.0
requests-oauthlib             2.0.0
setuptools                    65.5.1
six                           1.16.0
snowballstemmer               2.2.0
social-auth-app-django        5.4.0
social-auth-core              4.5.3
sqlparse                      0.4.4
typing_extensions             4.10.0
tzdata                        2024.1
tzlocal                       5.2
uritemplate                   4.1.1
urllib3                       2.2.1
vine                          5.1.0
wcwidth                       0.2.13
wheel                         0.45.0
zstandard                     0.22.0

uname -a output:
Linux 3a93f000f78d 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 GNU/Linux

I can post my models.py, serializers.py, views.py as well as docker-compose.yml sufficient for the reproduction if needed

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions