Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
325 changes: 325 additions & 0 deletions ddpui/api/dbt_automation_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
import uuid
import shutil
from pathlib import Path
from datetime import datetime
from dotenv import load_dotenv

Check warning on line 5 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L1-L5

Added lines #L1 - L5 were not covered by tests

from ninja import Router
from ninja.errors import HttpError

Check warning on line 8 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L7-L8

Added lines #L7 - L8 were not covered by tests

from django.db import transaction
from django.db.models import Q
from django.utils.text import slugify

Check warning on line 12 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L10-L12

Added lines #L10 - L12 were not covered by tests

from ddpui import auth
from ddpui.ddpdbt.dbt_service import setup_local_dbt_workspace
from ddpui.models.org_user import OrgUser
from ddpui.models.org import OrgDbt, OrgWarehouse, TransformType
from ddpui.models.dbt_automation import (

Check warning on line 18 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L14-L18

Added lines #L14 - L18 were not covered by tests
OrgDbtModelv1,
DbtOperation,
DbtEdgev1,
DbtNode,
)
from ddpui.models.canvaslock import CanvasLock

Check warning on line 24 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L24

Added line #L24 was not covered by tests

from ddpui.schemas.org_task_schema import DbtProjectSchema

Check warning on line 26 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L26

Added line #L26 was not covered by tests

from ddpui.schemas.dbt_automation_schema import (

Check warning on line 28 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L28

Added line #L28 was not covered by tests
CreateDbtModelNodePayload,
ChainOperationPayload,
EdgeConfig,
)
from ddpui.core.orgdbt_manager import DbtProjectManager
from ddpui.utils.taskprogress import TaskProgress
from ddpui.core.transformfunctions import validate_operation_config, check_canvas_locked
from ddpui.api.warehouse_api import get_warehouse_data
from ddpui.models.tasks import TaskProgressHashPrefix

Check warning on line 37 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L33-L37

Added lines #L33 - L37 were not covered by tests

from ddpui.core.dbtautomation_service import (

Check warning on line 39 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L39

Added line #L39 was not covered by tests
sync_sources_for_warehouse_v1,
OPERATIONS_DICT_VALIDATIONS,
generate_simulated_output,
)
from ddpui.auth import has_permission

Check warning on line 44 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L44

Added line #L44 was not covered by tests

from ddpui.utils.custom_logger import CustomLogger
from ddpui.utils.transform_workflow_helpers import (

Check warning on line 47 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L46-L47

Added lines #L46 - L47 were not covered by tests
from_orgdbtoperation,
)

dbtautomation_router = Router()
load_dotenv()
logger = CustomLogger("ddpui")

Check warning on line 53 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L51-L53

Added lines #L51 - L53 were not covered by tests


@dbtautomation_router.post("/dbtmodel/{model_uuid}/node/", auth=auth.CustomAuthMiddleware())
@has_permission(["can_create_dbt_model"])
def post_create_dbt_model_node(request, model_uuid: str, payload: CreateDbtModelNodePayload):

Check warning on line 58 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L56-L58

Added lines #L56 - L58 were not covered by tests
"""Move a dbt model to the canvas by creating a DbtNode"""

orguser: OrgUser = request.orguser
org = orguser.org

Check warning on line 62 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L61-L62

Added lines #L61 - L62 were not covered by tests

org_warehouse = OrgWarehouse.objects.filter(org=org).first()
if not org_warehouse:
raise HttpError(404, "please setup your warehouse first")

Check warning on line 66 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L64-L66

Added lines #L64 - L66 were not covered by tests

# make sure the orgdbt here is the one we create locally
orgdbt = OrgDbt.objects.filter(org=org, transform_type=TransformType.UI).first()
if not orgdbt:
raise HttpError(404, "dbt workspace not setup")

Check warning on line 71 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L69-L71

Added lines #L69 - L71 were not covered by tests

check_canvas_locked(orguser, payload.canvas_lock_id)

Check warning on line 73 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L73

Added line #L73 was not covered by tests

# create a DbtNode pointing to the dbt model
dbtmodel = OrgDbtModelv1.objects.filter(uuid=model_uuid).first()

Check warning on line 76 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L76

Added line #L76 was not covered by tests

if not dbtmodel:
raise HttpError(404, "dbt model not found")

Check warning on line 79 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L78-L79

Added lines #L78 - L79 were not covered by tests

# if the dbtmodel node is already there dont recreate it
if not DbtNode.objects.filter(dbtmodel=dbtmodel).exists():
DbtNode.objects.create(

Check warning on line 83 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L82-L83

Added lines #L82 - L83 were not covered by tests
orgdbt=orgdbt,
uuid=uuid.uuid4(),
dbtmodel=dbtmodel,
)

return {"success": 1}

Check warning on line 89 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L89

Added line #L89 was not covered by tests


@dbtautomation_router.post("/node/{node_uuid}/chain/", auth=auth.CustomAuthMiddleware())
@has_permission(["can_create_dbt_model"])
def post_chain_operation_node(request, node_uuid: str, payload: ChainOperationPayload):

Check warning on line 94 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L92-L94

Added lines #L92 - L94 were not covered by tests
"""Chain a new operation node on an existing node (uuid provided)"""

orguser: OrgUser = request.orguser
org = orguser.org

Check warning on line 98 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L97-L98

Added lines #L97 - L98 were not covered by tests

org_warehouse = OrgWarehouse.objects.filter(org=org).first()
if not org_warehouse:
raise HttpError(404, "please setup your warehouse first")

Check warning on line 102 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L100-L102

Added lines #L100 - L102 were not covered by tests

# make sure the orgdbt here is the one we create locally
orgdbt = OrgDbt.objects.filter(org=org, transform_type=TransformType.UI).first()
if not orgdbt:
raise HttpError(404, "dbt workspace not setup")

Check warning on line 107 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L105-L107

Added lines #L105 - L107 were not covered by tests

check_canvas_locked(orguser, payload.canvas_lock_id)

Check warning on line 109 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L109

Added line #L109 was not covered by tests

curr_node = DbtNode.objects.filter(uuid=node_uuid).first()

Check warning on line 111 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L111

Added line #L111 was not covered by tests

if not curr_node:
raise HttpError(404, "node not found")

Check warning on line 114 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L113-L114

Added lines #L113 - L114 were not covered by tests

if payload.op_type not in OPERATIONS_DICT_VALIDATIONS:
raise HttpError(400, "unknown operation")

Check warning on line 117 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L116-L117

Added lines #L116 - L117 were not covered by tests

# validate the operation config
op_config = OPERATIONS_DICT_VALIDATIONS[payload.op_type](**payload.config)

Check warning on line 120 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L120

Added line #L120 was not covered by tests

computed_output_cols = generate_simulated_output(op_config, payload.op_type)

Check warning on line 122 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L122

Added line #L122 was not covered by tests

with transaction.atomic():

Check warning on line 124 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L124

Added line #L124 was not covered by tests
# create a new DbtNode for the operation
dbtoperation = DbtOperation.objects.create(

Check warning on line 126 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L126

Added line #L126 was not covered by tests
uuid=uuid.uuid4(),
op_type=payload.op_type,
config=payload.config,
)

op_node = DbtNode.objects.create(

Check warning on line 132 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L132

Added line #L132 was not covered by tests
orgdbt=orgdbt,
uuid=uuid.uuid4(),
dbtoperation=dbtoperation,
output_cols=computed_output_cols,
)

# create an edge
DbtEdgev1.objects.create(uuid=uuid.uuid4(), from_node=curr_node, to_node=op_node)

Check warning on line 140 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L140

Added line #L140 was not covered by tests

return {"success": 1}

Check warning on line 142 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L142

Added line #L142 was not covered by tests


@dbtautomation_router.get("/graph/", auth=auth.CustomAuthMiddleware())
@has_permission(["can_view_dbt_workspace"])
def get_dbt_project_DAG(request):

Check warning on line 147 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L145-L147

Added lines #L145 - L147 were not covered by tests
"""Get the project DAG i.e. nodes and edges"""

orguser: OrgUser = request.orguser
org = orguser.org

Check warning on line 151 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L150-L151

Added lines #L150 - L151 were not covered by tests

org_warehouse = OrgWarehouse.objects.filter(org=org).first()
if not org_warehouse:
raise HttpError(404, "please setup your warehouse first")

Check warning on line 155 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L153-L155

Added lines #L153 - L155 were not covered by tests

# make sure the orgdbt here is the one we create locally
orgdbt = OrgDbt.objects.filter(org=org, gitrepo_url=None).first()
if not orgdbt:
raise HttpError(404, "dbt workspace not setup")

Check warning on line 160 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L158-L160

Added lines #L158 - L160 were not covered by tests

# Fetch all nodes and edges
nodes = DbtNode.objects.filter(orgdbt=orgdbt).select_related("dbtoperation", "dbtmodel")
edges = DbtEdgev1.objects.filter(

Check warning on line 164 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L163-L164

Added lines #L163 - L164 were not covered by tests
Q(from_node__orgdbt=orgdbt) | Q(to_node__orgdbt=orgdbt)
).select_related("from_node", "to_node")

# Convert nodes to the desired format
# TODO: we might need to change this because of what frontend needs
node_list = [

Check warning on line 170 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L170

Added line #L170 was not covered by tests
{
"id": node.uuid,
"dbtoperation": (
{
"id": node.dbtoperation.uuid,
"op_type": node.dbtoperation.op_type,
"config": node.dbtoperation.config,
}
if node.dbtoperation
else None
),
"dbtmodel": (
{
"id": node.dbtmodel.uuid,
"name": node.dbtmodel.name,
"schema": node.dbtmodel.schema,
"sql_path": node.dbtmodel.sql_path,
}
if node.dbtmodel
else None
),
"output_cols": node.output_cols,
}
for node in nodes
]

# Convert edges to the desired format
edge_list = [

Check warning on line 198 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L198

Added line #L198 was not covered by tests
{
"id": edge.uuid,
"source": edge.from_node.uuid,
"target": edge.to_node.uuid,
}
for edge in edges
]

# Return the DAG as a dictionary
return {

Check warning on line 208 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L208

Added line #L208 was not covered by tests
"nodes": node_list,
"edges": edge_list,
}


@dbtautomation_router.delete("/node/{node_uuid}/", auth=auth.CustomAuthMiddleware())
@has_permission(["can_create_dbt_model"])
def post_chain_operation_node(request, node_uuid: str, canvas_lock_id: str = None):

Check warning on line 216 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L214-L216

Added lines #L214 - L216 were not covered by tests
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Rename the duplicate function.

The function post_chain_operation_node is redefined here, overshadowing the version at line 87, causing confusion. Please rename this deletion endpoint to something like delete_dbt_node or remove_dbt_node to differentiate from the operation-chaining endpoint.

Apply this diff to rename the function:

-@dbtautomation_router.delete("/node/{node_uuid}/", auth=auth.CustomAuthMiddleware())
-@has_permission(["can_create_dbt_model"])
-def post_chain_operation_node(request, node_uuid: str, canvas_lock_id: str = None):
+@dbtautomation_router.delete("/node/{node_uuid}/", auth=auth.CustomAuthMiddleware())
+@has_permission(["can_create_dbt_model"])
+def delete_dbt_node(request, node_uuid: str, canvas_lock_id: str = None):
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def post_chain_operation_node(request, node_uuid: str, canvas_lock_id: str = None):
@dbtautomation_router.delete("/node/{node_uuid}/", auth=auth.CustomAuthMiddleware())
@has_permission(["can_create_dbt_model"])
def delete_dbt_node(request, node_uuid: str, canvas_lock_id: str = None):
🧰 Tools
🪛 Ruff (0.8.2)

206-206: Redefinition of unused post_chain_operation_node from line 87

(F811)

"""Delete a node (model or operation) and its edges"""

orguser: OrgUser = request.orguser
org = orguser.org

Check warning on line 220 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L219-L220

Added lines #L219 - L220 were not covered by tests

org_warehouse = OrgWarehouse.objects.filter(org=org).first()
if not org_warehouse:
raise HttpError(404, "please setup your warehouse first")

Check warning on line 224 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L222-L224

Added lines #L222 - L224 were not covered by tests

# make sure the orgdbt here is the one we create locally
orgdbt = OrgDbt.objects.filter(org=org, gitrepo_url=None).first()
if not orgdbt:
raise HttpError(404, "dbt workspace not setup")

Check warning on line 229 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L227-L229

Added lines #L227 - L229 were not covered by tests

check_canvas_locked(orguser, canvas_lock_id)

Check warning on line 231 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L231

Added line #L231 was not covered by tests

curr_node = DbtNode.objects.filter(uuid=node_uuid).first()

Check warning on line 233 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L233

Added line #L233 was not covered by tests

if not curr_node:
raise HttpError(404, "node not found")

Check warning on line 236 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L235-L236

Added lines #L235 - L236 were not covered by tests

# TODO: delete the stuff from dbt project on the disk

with transaction.atomic():
if curr_node.dbtoperation:

Check warning on line 241 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L240-L241

Added lines #L240 - L241 were not covered by tests
# delete the operation
curr_node.dbtoperation.delete()

Check warning on line 243 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L243

Added line #L243 was not covered by tests

# delete the edges
DbtEdgev1.objects.filter(Q(from_node=curr_node) | Q(to_node=curr_node)).delete()

Check warning on line 246 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L246

Added line #L246 was not covered by tests

# delete the node
curr_node.delete()

Check warning on line 249 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L249

Added line #L249 was not covered by tests

return {"success": 1}

Check warning on line 251 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L251

Added line #L251 was not covered by tests


@dbtautomation_router.get("/sources_models/", auth=auth.CustomAuthMiddleware())
@has_permission(["can_view_dbt_models"])
def get_dbtproject_sources_and_models(request, schema_name: str = None):

Check warning on line 256 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L254-L256

Added lines #L254 - L256 were not covered by tests
"""
Fetches all sources and models in a dbt project
"""
orguser: OrgUser = request.orguser
org = orguser.org

Check warning on line 261 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L260-L261

Added lines #L260 - L261 were not covered by tests

org_warehouse = OrgWarehouse.objects.filter(org=org).first()
if not org_warehouse:
raise HttpError(404, "please setup your warehouse first")

Check warning on line 265 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L263-L265

Added lines #L263 - L265 were not covered by tests

# make sure the orgdbt here is the one we create locally
orgdbt = OrgDbt.objects.filter(org=org, gitrepo_url=None).first()
if not orgdbt:
raise HttpError(404, "dbt workspace not setup")

Check warning on line 270 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L268-L270

Added lines #L268 - L270 were not covered by tests

query = OrgDbtModelv1.objects.filter(orgdbt=orgdbt)

Check warning on line 272 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L272

Added line #L272 was not covered by tests

if schema_name:
query = query.filter(schema=schema_name)

Check warning on line 275 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L274-L275

Added lines #L274 - L275 were not covered by tests

res = []

Check warning on line 277 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L277

Added line #L277 was not covered by tests
# TODO: might need to change depending on what the frontend needs to render
for orgdbt_model in query.all():
res.append(

Check warning on line 280 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L279-L280

Added lines #L279 - L280 were not covered by tests
{
"id": orgdbt_model.uuid,
"input_name": orgdbt_model.name,
"input_type": orgdbt_model.type,
"schema": orgdbt_model.schema,
"source_name": orgdbt_model.source_name,
}
)

return res

Check warning on line 290 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L290

Added line #L290 was not covered by tests


@dbtautomation_router.post("/sync_sources/", auth=auth.CustomAuthMiddleware())
@has_permission(["can_sync_sources"])
def sync_sources_in_warehouse(request):

Check warning on line 295 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L293-L295

Added lines #L293 - L295 were not covered by tests
"""Sync sources from a given schema."""
orguser: OrgUser = request.orguser
org = orguser.org

Check warning on line 298 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L297-L298

Added lines #L297 - L298 were not covered by tests

org_warehouse = OrgWarehouse.objects.filter(org=org).first()
if not org_warehouse:
raise HttpError(404, "Please set up your warehouse first")

Check warning on line 302 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L300-L302

Added lines #L300 - L302 were not covered by tests

orgdbt = OrgDbt.objects.filter(org=org, gitrepo_url=None).first()
if not orgdbt:
raise HttpError(404, "DBT workspace not set up")

Check warning on line 306 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L304-L306

Added lines #L304 - L306 were not covered by tests

task_id = str(uuid.uuid4())
hashkey = f"{TaskProgressHashPrefix.SYNCSOURCES.value}-{org.slug}"

Check warning on line 309 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L308-L309

Added lines #L308 - L309 were not covered by tests

taskprogress = TaskProgress(

Check warning on line 311 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L311

Added line #L311 was not covered by tests
task_id=task_id,
hashkey=hashkey,
expire_in_seconds=10 * 60, # max 10 minutes)
)
taskprogress.add(

Check warning on line 316 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L316

Added line #L316 was not covered by tests
{
"message": "Started syncing sources",
"status": "runnning",
}
)

sync_sources_for_warehouse_v1.delay(orgdbt.id, org_warehouse.id, task_id, hashkey)

Check warning on line 323 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L323

Added line #L323 was not covered by tests

return {"task_id": task_id, "hashkey": hashkey}

Check warning on line 325 in ddpui/api/dbt_automation_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/dbt_automation_api.py#L325

Added line #L325 was not covered by tests
Loading
Loading