From e30e059b9ed021892ebadfb2915bedb709cc1350 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@ess.eu> Date: Fri, 2 Oct 2020 20:40:08 +0200 Subject: [PATCH] Update Python and requirements - Updating rq to 1.0 requires some work due to incompatible changes (move_to_failed_queue() has been removed) - Updating sqlalchemy to 1.3 made some tests fail. JIRA INFRA-2649 #action In Progress --- Dockerfile | 3 +- app/utils.py | 2 +- requirements-to-freeze.txt | 8 +-- requirements.txt | 95 ++++++++++++++++++------------------ tests/functional/test_api.py | 28 +++++------ 5 files changed, 70 insertions(+), 66 deletions(-) diff --git a/Dockerfile b/Dockerfile index 853f56b..ee2a9f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-slim as base +FROM python:3.8-slim as base # Install Python dependencies in an intermediate image # as some requires a compiler (psycopg2) @@ -37,6 +37,7 @@ RUN apt-get update \ COPY requirements.txt /requirements.txt RUN python -m venv /venv \ && . /venv/bin/activate \ + && pip install --no-cache-dir --upgrade pip \ && pip install --no-cache-dir -r /requirements.txt ARG CSENTRY_BUILD diff --git a/app/utils.py b/app/utils.py index 1995f55..f109ce2 100644 --- a/app/utils.py +++ b/app/utils.py @@ -186,7 +186,7 @@ def get_query(query, model, **kwargs): # Always apply filtering on the given model for key, value in kwargs.items(): query = query.filter(getattr(model, key) == value) - except (sa.exc.InvalidRequestError, AttributeError) as e: + except (sa.exc.InvalidRequestError, sa.exc.ArgumentError, AttributeError) as e: current_app.logger.warning(f"Invalid query arguments: {e}") raise CSEntryError("Invalid query arguments", status_code=422) return query diff --git a/requirements-to-freeze.txt b/requirements-to-freeze.txt index 042e8e5..8ed87da 100644 --- a/requirements-to-freeze.txt +++ b/requirements-to-freeze.txt @@ -19,11 +19,13 @@ python-dateutil pyyaml qrcode whitenoise -ansible-tower-cli -rq -rq-dashboard +ansible-tower-cli<3.3.9 +rq<1.0 +rq-dashboard<0.5.0 sentry-sdk +sqlalchemy<1.3 sqlalchemy-citext sqlalchemy-continuum openpyxl uwsgi +WTForms>=2.1,<2.2 diff --git a/requirements.txt b/requirements.txt index 21ed0ab..effc19c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,54 +1,55 @@ -alembic==1.0.5 -ansible-tower-cli==3.3.0 -arrow==0.12.1 +alembic==1.4.3 +ansible-tower-cli==3.3.8 +arrow==0.17.0 blinker==1.4 -certifi==2018.11.29 +cachelib==0.1.1 +certifi==2020.6.20 chardet==3.0.4 -Click==7.0 -colorama==0.4.1 -elasticsearch==7.0.4 +click==7.1.2 +colorama==0.4.4 +elasticsearch==7.9.1 et-xmlfile==1.0.1 -Flask==1.0.2 -Flask-Admin==1.5.2 -Flask-Caching==1.4.0 -Flask-DebugToolbar==0.10.1 -Flask-JWT-Extended==3.13.1 +Flask==1.1.2 +Flask-Admin==1.5.6 +Flask-Caching==1.9.0 +Flask-DebugToolbar==0.11.0 +Flask-JWT-Extended==3.24.1 flask-ldap3-login==0.9.16 -Flask-Login==0.4.1 +Flask-Login==0.5.0 Flask-Mail==0.9.1 -Flask-Migrate==2.3.1 -Flask-Redis==0.3.0 -Flask-Session==0.3.1 -Flask-SQLAlchemy==2.3.2 -Flask-WTF==0.14.2 -idna==2.7 +Flask-Migrate==2.5.3 +flask-redis==0.4.0 +Flask-Session==0.3.2 +Flask-SQLAlchemy==2.4.4 +Flask-WTF==0.14.3 +idna==2.10 itsdangerous==1.1.0 -jdcal==1.4 -Jinja2==2.10 -ldap3==2.5.1 -Mako==1.0.7 -MarkupSafe==1.1.0 -openpyxl==2.5.12 -Pillow==5.3.0 -psycopg2==2.7.6.1 -pyasn1==0.4.4 -PyJWT==1.6.4 -python-dateutil==2.7.5 -python-editor==1.0.3 -PyYAML==3.13 -qrcode==6.0 -redis==2.10.6 -requests==2.20.1 -rq==0.12.0 -rq-dashboard==0.3.12 -sentry-sdk==0.7.10 -six==1.11.0 -SQLAlchemy==1.2.14 -sqlalchemy-citext==1.3.post0 -SQLAlchemy-Continuum==1.3.6 -SQLAlchemy-Utils==0.33.8 -urllib3==1.24.1 -uwsgi==2.0.18 -Werkzeug==0.14.1 -whitenoise==4.1.2 +jdcal==1.4.1 +Jinja2==2.11.2 +ldap3==2.8.1 +Mako==1.1.3 +MarkupSafe==1.1.1 +openpyxl==3.0.5 +Pillow==8.0.0 +psycopg2==2.8.6 +pyasn1==0.4.8 +PyJWT==1.7.1 +python-dateutil==2.8.1 +python-editor==1.0.4 +PyYAML==5.3.1 +qrcode==6.1 +redis==3.5.3 +requests==2.24.0 +rq==0.13.0 +rq-dashboard==0.4.0 +sentry-sdk==0.19.1 +six==1.15.0 +SQLAlchemy==1.2.19 +sqlalchemy-citext==1.7.0 +SQLAlchemy-Continuum==1.3.11 +SQLAlchemy-Utils==0.36.8 +urllib3==1.25.11 +uWSGI==2.0.19.1 +Werkzeug==1.0.1 +whitenoise==5.2.0 WTForms==2.1 diff --git a/tests/functional/test_api.py b/tests/functional/test_api.py index 8843e2a..79b70b1 100644 --- a/tests/functional/test_api.py +++ b/tests/functional/test_api.py @@ -312,7 +312,7 @@ def test_create_generic_model(endpoint, client, user_token): response = post(client, f"{API_URL}/{endpoint}", data=data, token=user_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) response = post( @@ -320,7 +320,7 @@ def test_create_generic_model(endpoint, client, user_token): ) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) response = post( @@ -328,7 +328,7 @@ def test_create_generic_model(endpoint, client, user_token): ) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) data = {"name": "Bar", "description": "Bar description"} @@ -397,7 +397,7 @@ def test_create_item(client, user_token): response = post(client, f"{API_URL}/inventory/items", data=data2, token=user_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -543,7 +543,7 @@ def test_patch_item_integrity_error(client, user_token, item_factory): ) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -911,7 +911,7 @@ def test_create_network(client, admin_token, network_scope_factory): ) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -1318,7 +1318,7 @@ def test_create_interface(client, host, network_192_168_1, no_login_check_token) ) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -1510,7 +1510,7 @@ def test_create_mac(client, item_factory, user_token): response = post(client, f"{API_URL}/inventory/macs", data=data, token=user_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -1567,7 +1567,7 @@ def test_create_ansible_group(client, admin_token): response = post(client, f"{API_URL}/network/groups", data=data, token=admin_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -1784,7 +1784,7 @@ def test_create_host(client, device_type_factory, user_token): response = post(client, f"{API_URL}/network/hosts", data=data, token=user_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -1932,7 +1932,7 @@ def test_create_domain(client, admin_token): response = post(client, f"{API_URL}/network/domains", data=data, token=admin_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -2906,7 +2906,7 @@ def test_delete_network_scope_with_network_fail( ) check_response_message( response, - '(psycopg2.IntegrityError) null value in column "scope_id" violates not-null constraint', + '(psycopg2.errors.NotNullViolation) null value in column "scope_id" violates not-null constraint', 422, ) @@ -2930,7 +2930,7 @@ def test_delete_network_with_host_fail( ) check_response_message( response, - '(psycopg2.IntegrityError) null value in column "network_id" violates not-null constraint', + '(psycopg2.errors.NotNullViolation) null value in column "network_id" violates not-null constraint', 422, ) @@ -2962,7 +2962,7 @@ def test_delete_domain_with_network_fail(client, domain, network_factory, admin_ ) check_response_message( response, - '(psycopg2.IntegrityError) null value in column "domain_id" violates not-null constraint', + '(psycopg2.errors.NotNullViolation) null value in column "domain_id" violates not-null constraint', 422, ) -- GitLab