From 2ea6f363b828b6b59800972ba3d978e62288740e Mon Sep 17 00:00:00 2001 From: eastandwestwind Date: Wed, 18 Dec 2024 15:45:10 +0100 Subject: [PATCH] lint, etc --- ...09be3_adding_foreign_key_on_fides_key_for_.py | 3 +-- ...da77c468_add_data_migration_to_reactivate_.py | 2 -- .../api/api/v1/endpoints/generic_overrides.py | 16 ++++++++++++---- src/fides/api/models/sql_models.py | 2 +- tests/ctl/core/test_taxonomy_models.py | 1 + .../api/v1/endpoints/test_taxonomy_overrides.py | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/fides/api/alembic/migrations/versions/10c6b7709be3_adding_foreign_key_on_fides_key_for_.py b/src/fides/api/alembic/migrations/versions/10c6b7709be3_adding_foreign_key_on_fides_key_for_.py index fb9f6cb6d0..7c7a5bfe37 100644 --- a/src/fides/api/alembic/migrations/versions/10c6b7709be3_adding_foreign_key_on_fides_key_for_.py +++ b/src/fides/api/alembic/migrations/versions/10c6b7709be3_adding_foreign_key_on_fides_key_for_.py @@ -6,9 +6,8 @@ """ -from alembic import op import sqlalchemy as sa - +from alembic import op # revision identifiers, used by Alembic. revision = "10c6b7709be3" diff --git a/src/fides/api/alembic/migrations/versions/ae65da77c468_add_data_migration_to_reactivate_.py b/src/fides/api/alembic/migrations/versions/ae65da77c468_add_data_migration_to_reactivate_.py index 0c3655ddec..ec5c845d89 100644 --- a/src/fides/api/alembic/migrations/versions/ae65da77c468_add_data_migration_to_reactivate_.py +++ b/src/fides/api/alembic/migrations/versions/ae65da77c468_add_data_migration_to_reactivate_.py @@ -8,11 +8,9 @@ import sqlalchemy as sa from alembic import op - from sqlalchemy import text from sqlalchemy.engine import Connection - # revision identifiers, used by Alembic. revision = "ae65da77c468" down_revision = "10c6b7709be3" diff --git a/src/fides/api/api/v1/endpoints/generic_overrides.py b/src/fides/api/api/v1/endpoints/generic_overrides.py index 821bd7e10c..ba5ee29181 100644 --- a/src/fides/api/api/v1/endpoints/generic_overrides.py +++ b/src/fides/api/api/v1/endpoints/generic_overrides.py @@ -9,7 +9,7 @@ from sqlalchemy.orm import Session from sqlalchemy.sql.expression import select from starlette import status -from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY, HTTP_404_NOT_FOUND +from starlette.status import HTTP_404_NOT_FOUND, HTTP_422_UNPROCESSABLE_ENTITY from fides.api.api.deps import get_db from fides.api.common_exceptions import KeyOrNameAlreadyExists @@ -28,15 +28,15 @@ DataUse, DataUseCreateOrUpdate, ) -from fides.api.util.errors import ForbiddenIsDefaultTaxonomyError +from fides.api.util.errors import FidesError, ForbiddenIsDefaultTaxonomyError from fides.api.util.filter_utils import apply_filters_to_query from fides.common.api.scope_registry import ( DATA_CATEGORY_CREATE, + DATA_CATEGORY_UPDATE, DATA_SUBJECT_CREATE, DATA_USE_CREATE, - DATASET_READ, DATA_USE_UPDATE, - DATA_CATEGORY_UPDATE, + DATASET_READ, ) from fides.common.api.v1.urn_registry import V1_URL_PREFIX @@ -162,6 +162,10 @@ def validate_and_create_taxonomy( """ Validate and create a taxonomy element. """ + if not data.fides_key: + raise FidesError( + f"Fides key is required to create a {model.__name__} resource" + ) if isinstance(model, ModelWithDefaultField) and data.is_default: raise ForbiddenIsDefaultTaxonomyError( model.__name__, data.fides_key, action="create" @@ -181,6 +185,10 @@ def validate_and_update_taxonomy( """ Validate and update a taxonomy element. """ + if not data.fides_key: + raise FidesError( + f"Fides key is required to update {resource.__name__}" + ) if isinstance(resource, ModelWithDefaultField) and data.is_default: raise ForbiddenIsDefaultTaxonomyError( resource.__name__, data.fides_key, action="update" diff --git a/src/fides/api/models/sql_models.py b/src/fides/api/models/sql_models.py index 0f069e52c0..6d3d98ad72 100644 --- a/src/fides/api/models/sql_models.py +++ b/src/fides/api/models/sql_models.py @@ -36,7 +36,7 @@ from sqlalchemy.exc import IntegrityError from sqlalchemy.ext.asyncio import AsyncSession, async_object_session from sqlalchemy.ext.hybrid import hybrid_property -from sqlalchemy.orm import Session, relationship +from sqlalchemy.orm import RelationshipProperty, Session, relationship from sqlalchemy.sql import Select from sqlalchemy.sql.elements import Case from sqlalchemy.sql.sqltypes import DateTime diff --git a/tests/ctl/core/test_taxonomy_models.py b/tests/ctl/core/test_taxonomy_models.py index c9358ef2c9..546100a35b 100644 --- a/tests/ctl/core/test_taxonomy_models.py +++ b/tests/ctl/core/test_taxonomy_models.py @@ -3,6 +3,7 @@ import pytest from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import Session + from fides.api.models.sql_models import DataUse diff --git a/tests/ops/api/v1/endpoints/test_taxonomy_overrides.py b/tests/ops/api/v1/endpoints/test_taxonomy_overrides.py index 589d35a535..f028cdb956 100644 --- a/tests/ops/api/v1/endpoints/test_taxonomy_overrides.py +++ b/tests/ops/api/v1/endpoints/test_taxonomy_overrides.py @@ -9,8 +9,8 @@ from fides.common.api.scope_registry import ( DATA_USE, DATA_USE_CREATE, - STORAGE_READ, DATA_USE_UPDATE, + STORAGE_READ, ) from fides.common.api.v1.urn_registry import V1_URL_PREFIX