fix(translate): fix job creation tab navigation and preview validation
- frontend: add to reload job data on param change after goto - frontend: set existingJob from createJob response for immediate tabs - frontend: suppress error toasts for schedule 404 (normal state) - frontend: conditional ScheduleConfig mount to avoid 'new' job loading - backend: skip preview check for jobs with direct Superset datasource - backend: add orthogonal test for datasource+no-preview success case
This commit is contained in:
@@ -191,8 +191,30 @@ class TestTranslationOrchestrator:
|
||||
assert run.status == "PENDING"
|
||||
assert run.job_id == "job-123"
|
||||
|
||||
# region test_start_run_with_datasource_no_preview_succeeds [TYPE Function]
|
||||
# @PURPOSE: Manual run with Superset datasource succeeds even without accepted preview session.
|
||||
def test_start_run_with_datasource_no_preview_succeeds(
|
||||
self,
|
||||
mock_job: MagicMock,
|
||||
) -> None:
|
||||
db = MagicMock()
|
||||
config_manager = MagicMock()
|
||||
|
||||
# Mock job query — job HAS a Superset datasource (fixture sets source_datasource_id="42")
|
||||
db.query.return_value.filter.return_value.first.return_value = mock_job
|
||||
|
||||
# No accepted preview session mock — not needed because datasource bypasses preview check.
|
||||
# validate_job_preconditions skips preview query when source_datasource_id is set.
|
||||
# This verifies the gating logic: datasource → no preview required → run proceeds.
|
||||
|
||||
orch = TranslationOrchestrator(db, config_manager, "test-user")
|
||||
run = orch.start_run(job_id="job-123")
|
||||
|
||||
assert run.status == "PENDING"
|
||||
assert run.job_id == "job-123"
|
||||
|
||||
# region test_start_run_missing_preview_raises [TYPE Function]
|
||||
# @PURPOSE: Manual run without accepted preview raises ValueError.
|
||||
# @PURPOSE: Manual run without accepted preview raises ValueError when job has no direct datasource.
|
||||
def test_start_run_missing_preview_raises(
|
||||
self,
|
||||
mock_job: MagicMock,
|
||||
@@ -200,7 +222,9 @@ class TestTranslationOrchestrator:
|
||||
db = MagicMock()
|
||||
config_manager = MagicMock()
|
||||
|
||||
# Mock job query
|
||||
# Mock job query — job WITHOUT a Superset datasource, so preview is required
|
||||
mock_job.source_datasource_id = None
|
||||
mock_job.environment_id = None
|
||||
db.query.return_value.filter.return_value.first.return_value = mock_job
|
||||
|
||||
# No accepted preview session
|
||||
|
||||
@@ -39,19 +39,23 @@ def validate_job_preconditions(
|
||||
"Select a translation column before running."
|
||||
)
|
||||
if not is_scheduled:
|
||||
from ...models.translate import TranslationPreviewSession
|
||||
accepted_session = (
|
||||
db_session.query(TranslationPreviewSession)
|
||||
.filter(
|
||||
TranslationPreviewSession.job_id == job.id,
|
||||
TranslationPreviewSession.status == "APPLIED",
|
||||
)
|
||||
.order_by(TranslationPreviewSession.created_at.desc())
|
||||
.first()
|
||||
)
|
||||
if not accepted_session:
|
||||
raise ValueError(
|
||||
f"Job '{job.id}' has no accepted preview session. "
|
||||
"Run and accept a preview before executing a manual translation run."
|
||||
# Jobs with a direct Superset datasource can fetch rows from Superset directly
|
||||
# (see RunSourceFetcher.fetch_source_rows), so they don't need a preview session.
|
||||
# Only require an accepted preview for jobs without a configured datasource.
|
||||
if not bool(job.source_datasource_id):
|
||||
from ...models.translate import TranslationPreviewSession
|
||||
accepted_session = (
|
||||
db_session.query(TranslationPreviewSession)
|
||||
.filter(
|
||||
TranslationPreviewSession.job_id == job.id,
|
||||
TranslationPreviewSession.status == "APPLIED",
|
||||
)
|
||||
.order_by(TranslationPreviewSession.created_at.desc())
|
||||
.first()
|
||||
)
|
||||
if not accepted_session:
|
||||
raise ValueError(
|
||||
f"Job '{job.id}' has no accepted preview session. "
|
||||
"Run and accept a preview before executing a manual translation run."
|
||||
)
|
||||
# #endregion validate_job_preconditions
|
||||
|
||||
Reference in New Issue
Block a user