Skip to content

Commit

Permalink
GTC-2618 Clean up version append
Browse files Browse the repository at this point in the history
  • Loading branch information
manukala6 committed Jun 21, 2024
1 parent 4edd3b4 commit 4e52f20
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions app/routes/datasets/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -45,6 +44,7 @@
CreationOptions,
CreationOptionsResponse,
creation_option_factory,
TableDrivers
)
from ...models.pydantic.extent import Extent, ExtentResponse
from ...models.pydantic.metadata import (
Expand Down Expand Up @@ -242,29 +242,34 @@ 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
)

# 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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4e52f20

Please sign in to comment.