Skip to content

Commit

Permalink
fix : Pipeline Version parameters were converted to snake_case with i…
Browse files Browse the repository at this point in the history
…nvalid format (#865)

* Convert names by default

* Fix bug

* Upgrade recommended

* Upgrade recommended

* Upgrade recommended

* Remove usage of deprecated convert kwargs

* Convert camel case to snake case

* Add unit test

* More renames

* Revert a useless rename
  • Loading branch information
YolanFery authored Dec 9, 2024
1 parent c60c1bb commit e1a1b2c
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 148 deletions.
1 change: 1 addition & 0 deletions config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ def serialize_opaque_id(value):
*config_bindables,
snake_case_fallback_resolvers,
],
convert_names_case=True,
directives=identity_directives,
)
5 changes: 1 addition & 4 deletions hexa/databases/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
EnumType,
MutationType,
ObjectType,
convert_kwargs_to_snake_case,
load_schema_from_path,
)
from django.core.exceptions import PermissionDenied
Expand Down Expand Up @@ -34,7 +33,6 @@


@database_object.field("tables")
@convert_kwargs_to_snake_case
def resolve_database_tables(workspace, info, page=1, per_page=15, **kwargs):
tables = get_database_definition(
workspace=workspace,
Expand Down Expand Up @@ -78,7 +76,6 @@ def resolve_database_table_sample(table, info, **kwargs):


@database_table_object.field("rows")
@convert_kwargs_to_snake_case
def resolve_workspace_table_rows(
table,
info,
Expand Down Expand Up @@ -110,7 +107,7 @@ def resolve_generate_new_database_password(_, info, **kwargs):
input = kwargs["input"]
try:
workspace: Workspace = Workspace.objects.filter_for_user(request.user).get(
slug=input["workspaceSlug"]
slug=input["workspace_slug"]
)

workspace.generate_new_database_password(principal=request.user)
Expand Down
22 changes: 11 additions & 11 deletions hexa/datasets/schema/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def resolve_create_dataset(_, info, **kwargs):

try:
workspace = Workspace.objects.filter_for_user(request.user).get(
slug=mutation_input["workspaceSlug"]
slug=mutation_input["workspace_slug"]
)
dataset = Dataset.objects.create_if_has_perm(
principal=request.user,
Expand Down Expand Up @@ -49,7 +49,7 @@ def resolve_update_dataset(_, info, **kwargs):

try:
dataset = Dataset.objects.filter_for_user(request.user).get(
id=mutation_input["datasetId"]
id=mutation_input["dataset_id"]
)

dataset.update_if_has_perm(
Expand Down Expand Up @@ -89,7 +89,7 @@ def resolve_create_dataset_version(_, info, **kwargs):

try:
dataset = Dataset.objects.filter_for_user(request.user).get(
id=mutation_input["datasetId"]
id=mutation_input["dataset_id"]
)

version = DatasetVersion.objects.create_if_has_perm(
Expand Down Expand Up @@ -135,7 +135,7 @@ def resolve_delete_dataset_version(_, info, **kwargs):

try:
version = DatasetVersion.objects.filter_for_user(request.user).get(
id=mutation_input["versionId"]
id=mutation_input["version_id"]
)

version.delete_if_has_perm(principal=request.user)
Expand All @@ -154,10 +154,10 @@ def resolve_link_dataset(_, info, **kwargs):

try:
dataset = Dataset.objects.filter_for_user(request.user).get(
id=mutation_input["datasetId"]
id=mutation_input["dataset_id"]
)
workspace = Workspace.objects.filter_for_user(request.user).get(
slug=mutation_input["workspaceSlug"]
slug=mutation_input["workspace_slug"]
)

if not request.user.has_perm("datasets.link_dataset", (dataset, workspace)):
Expand Down Expand Up @@ -202,7 +202,7 @@ def resolve_generate_upload_url(_, info, **kwargs):

try:
version = DatasetVersion.objects.filter_for_user(request.user).get(
id=mutation_input["versionId"]
id=mutation_input["version_id"]
)
if version.id != version.dataset.latest_version.id:
return {"success": False, "errors": ["LOCKED_VERSION"]}
Expand All @@ -211,7 +211,7 @@ def resolve_generate_upload_url(_, info, **kwargs):
if get_blob(full_uri) is not None:
return {"success": False, "errors": ["ALREADY_EXISTS"]}

upload_url = generate_upload_url(full_uri, mutation_input["contentType"])
upload_url = generate_upload_url(full_uri, mutation_input["content_type"])

return {"success": True, "errors": [], "upload_url": upload_url}
except ValidationError:
Expand All @@ -229,7 +229,7 @@ def resolve_create_version_file(_, info, **kwargs):

try:
version = DatasetVersion.objects.filter_for_user(request.user).get(
id=mutation_input["versionId"]
id=mutation_input["version_id"]
)

if version.id != version.dataset.latest_version.id:
Expand All @@ -246,7 +246,7 @@ def resolve_create_version_file(_, info, **kwargs):
principal=request.user,
dataset_version=version,
uri=version.get_full_uri(mutation_input["uri"]),
content_type=mutation_input["contentType"],
content_type=mutation_input["content_type"],
)

file.generate_metadata()
Expand All @@ -270,7 +270,7 @@ def resolve_version_file_download(_, info, **kwargs):

try:
file = DatasetVersionFile.objects.filter_for_user(request.user).get(
id=mutation_input["fileId"]
id=mutation_input["file_id"]
)
# We only get the file if the user or pipeline can see the dataset either by direct access or via a link.
# FIXME: Implement a better permission system to be able to check if the pipeline can download the file.
Expand Down
6 changes: 3 additions & 3 deletions hexa/datasets/schema/queries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ariadne import QueryType, convert_kwargs_to_snake_case
from ariadne import QueryType

from hexa.core.graphql import result_page

Expand All @@ -13,7 +13,6 @@


@datasets_queries.field("datasets")
@convert_kwargs_to_snake_case
def resolve_datasets(_, info, query=None, page=1, per_page=15):
request = info.context["request"]
qs = Dataset.objects.filter_for_user(request.user).order_by("-updated_at")
Expand Down Expand Up @@ -67,7 +66,8 @@ def resolve_dataset_link_by_slug(_, info, **kwargs):
request = info.context["request"]
try:
return DatasetLink.objects.filter_for_user(request.user).get(
dataset__slug=kwargs["datasetSlug"], workspace__slug=kwargs["workspaceSlug"]
dataset__slug=kwargs["dataset_slug"],
workspace__slug=kwargs["workspace_slug"],
)
except DatasetLink.DoesNotExist:
return None
Expand Down
8 changes: 4 additions & 4 deletions hexa/datasets/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def resolve_workspace_datasets(obj: Workspace, info, pinned=None, query=None, **
return result_page(
queryset=qs,
page=kwargs.get("page", 1),
per_page=kwargs.get("perPage", 15),
per_page=kwargs.get("per_page", 15),
)


Expand All @@ -80,7 +80,7 @@ def resolve_dataset_versions(obj: Dataset, info, **kwargs):
return result_page(
obj.versions.all(),
page=kwargs.get("page", 1),
per_page=kwargs.get("perPage", 15),
per_page=kwargs.get("per_page", 15),
)


Expand All @@ -102,7 +102,7 @@ def resolve_dataset_links(obj: Dataset, info, **kwargs):
return result_page(
obj.links.filter(~Q(workspace=obj.workspace)).order_by("-updated_at"),
page=kwargs.get("page", 1),
per_page=kwargs.get("perPage", 15),
per_page=kwargs.get("per_page", 15),
)


Expand Down Expand Up @@ -176,7 +176,7 @@ def resolve_version_files(obj: DatasetVersion, info, **kwargs):
return result_page(
obj.files.all(),
page=kwargs.get("page", 1),
per_page=kwargs.get("perPage", 15),
per_page=kwargs.get("per_page", 15),
)


Expand Down
16 changes: 8 additions & 8 deletions hexa/files/schema/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def resolve_delete_bucket_object(_, info, **kwargs):
mutation_input = kwargs["input"]
try:
workspace = Workspace.objects.filter_for_user(request.user).get(
slug=mutation_input["workspaceSlug"]
slug=mutation_input["workspace_slug"]
)
if not request.user.has_perm("files.delete_object", workspace):
return {"success": False, "errors": ["PERMISSION_DENIED"]}

storage.delete_object(workspace.bucket_name, mutation_input["objectKey"])
storage.delete_object(workspace.bucket_name, mutation_input["object_key"])
return {"success": True, "errors": []}
except (storage.exceptions.NotFound, Workspace.DoesNotExist):
return {"success": False, "errors": ["NOT_FOUND"]}
Expand All @@ -31,11 +31,11 @@ def resolve_prepare_download_object(_, info, **kwargs):

try:
workspace = Workspace.objects.filter_for_user(request.user).get(
slug=mutation_input["workspaceSlug"]
slug=mutation_input["workspace_slug"]
)
if not request.user.has_perm("files.download_object", workspace):
return {"success": False, "errors": ["PERMISSION_DENIED"]}
object_key = mutation_input["objectKey"]
object_key = mutation_input["object_key"]
download_url = storage.generate_download_url(
workspace.bucket_name, object_key, force_attachment=True
)
Expand All @@ -57,13 +57,13 @@ def resolve_prepare_upload_object(_, info, **kwargs):

try:
workspace = Workspace.objects.filter_for_user(request.user).get(
slug=mutation_input["workspaceSlug"]
slug=mutation_input["workspace_slug"]
)
if not request.user.has_perm("files.create_object", workspace):
return {"success": False, "errors": ["PERMISSION_DENIED"]}
object_key = mutation_input["objectKey"]
object_key = mutation_input["object_key"]
upload_url = storage.generate_upload_url(
workspace.bucket_name, object_key, mutation_input.get("contentType")
workspace.bucket_name, object_key, mutation_input.get("content_type")
)

return {"success": True, "upload_url": upload_url, "errors": []}
Expand All @@ -78,7 +78,7 @@ def resolve_create_bucket_folder(_, info, **kwargs):

try:
workspace = Workspace.objects.filter_for_user(request.user).get(
slug=mutation_input["workspaceSlug"]
slug=mutation_input["workspace_slug"]
)
if not request.user.has_perm("files.create_object", workspace):
return {"success": False, "errors": ["PERMISSION_DENIED"]}
Expand Down
3 changes: 1 addition & 2 deletions hexa/files/schema/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ariadne import ObjectType, convert_kwargs_to_snake_case
from ariadne import ObjectType
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpRequest

Expand Down Expand Up @@ -41,7 +41,6 @@ def resolve_bucket_name(workspace, info, **kwargs):


@bucket_object.field("objects")
@convert_kwargs_to_snake_case
def resolve_bucket_objects(
workspace,
info,
Expand Down
6 changes: 3 additions & 3 deletions hexa/metadata/schema/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def resolve_add_metadata(_, info, **kwargs):
user = info.context["request"].user

try:
model_instance = mutation_input.get("targetId")
model_instance = mutation_input.get("target_id")
if model_instance.can_update_metadata(user):
model_instance.add_attribute(
key=mutation_input["key"],
Expand All @@ -36,7 +36,7 @@ def resolve_delete_metadata(_, info, **kwargs):
user = info.context["request"].user

try:
model_instance = mutation_input.get("targetId")
model_instance = mutation_input.get("target_id")
if model_instance.can_delete_metadata(user):
model_instance.delete_attribute(key=mutation_input["key"])
return {"success": True, "errors": []}
Expand All @@ -56,7 +56,7 @@ def resolve_edit_metadata(_, info, **kwargs):
user = info.context["request"].user

try:
model_instance = mutation_input.get("targetId")
model_instance = mutation_input.get("target_id")

if model_instance.can_update_metadata(user):
model_instance.update_or_create_attribute(
Expand Down
2 changes: 1 addition & 1 deletion hexa/metadata/schema/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def resolve_metadata_query(_, info, **kwargs):
request = info.context["request"]
user = request.user
model_instance = kwargs.get("targetId")
model_instance = kwargs.get("target_id")
if model_instance.can_view_metadata(user):
return model_instance.attributes.all()

Expand Down
2 changes: 1 addition & 1 deletion hexa/notebooks/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def resolve_launch_notebook_server(_, info, input, **kwargs):
Jupyterhub.
"""
request: HttpRequest = info.context["request"]
workspace_slug = input["workspaceSlug"]
workspace_slug = input["workspace_slug"]

try:
workspace = Workspace.objects.filter_for_user(request.user).get(
Expand Down
Loading

0 comments on commit e1a1b2c

Please sign in to comment.