diff --git a/app/routes/datasets/versions.py b/app/routes/datasets/versions.py index 081ee3ac..5288357b 100644 --- a/app/routes/datasets/versions.py +++ b/app/routes/datasets/versions.py @@ -13,7 +13,6 @@ from copy import deepcopy from typing import Any, Dict, List, Optional, Sequence, Tuple, Union, cast from urllib.parse import urlparse -import fiona from fastapi import ( APIRouter, @@ -45,6 +44,7 @@ CreationOptions, CreationOptionsResponse, creation_option_factory, + TableDrivers ) from ...models.pydantic.extent import Extent, ExtentResponse from ...models.pydantic.metadata import ( @@ -242,21 +242,26 @@ async def append_to_version( input_data["creation_options"]["source_uri"] = request.source_uri # If source_driver is "text", this is a datapump request - if input_data["creation_options"]["source_driver"] != "text": + if input_data["creation_options"]["source_driver"] != TableDrivers.text: # Verify that source_driver is not None if input_data["creation_options"]["source_driver"] is None: raise HTTPException( status_code=400, detail="Source driver must be specified for non-datapump requests." ) + + # Verify that source_driver matches the original source_driver + if input_data["creation_options"]["source_driver"] != request.source_driver: + raise HTTPException( + status_code=400, + detail="source_driver must match the original source_driver." + ) - # Append the new layers to the existing ones - if input_data["creation_options"].get("layers") is None: # ERROR: layers is not defined + # Use layers from request if provided, otherwise leave empty + if request.layers is not None: input_data["creation_options"]["layers"] = request.layers - elif request.layers is not None: - input_data["creation_options"]["layers"] += request.layers else: - input_data["creation_options"]["layers"] = request.layers + input_data["creation_options"]["layers"] = None background_tasks.add_task( append_default_asset, dataset, version, input_data, default_asset.asset_id @@ -264,7 +269,7 @@ async def append_to_version( # We now want to append the new uris to the existing ones and update the asset update_data = {"creation_options": deepcopy(default_asset.creation_options)} - update_data["creation_options"]["source_uri"] += request.source_uri # ERROR: only one source_uri is allowed + update_data["creation_options"]["source_uri"] += request.source_uri if input_data["creation_options"].get("layers") is not None: if update_data["creation_options"]["layers"] is not None: update_data["creation_options"]["layers"] += request.layers @@ -559,18 +564,6 @@ async def _version_response( return VersionResponse(data=Version(**data)) -#def _verify_layer_exists(source_uri: List[str], layes: List[str]) -> None: -# with fiona.open(source_uri[0].replace("s3://", "/vsizip//vsis3/"), "r") as src: -# layers = src.layer_names -# for layer in layers: -# if layer in layers: -# return -# else: -# raise HTTPException( -# status_code=400, -# detail=f"Layer {layer} not found in source file." -# ) - def _verify_source_file_access(sources: List[str]) -> None: # TODO: