fix(translate): datasource change not persisted on save + preview column cleanup
Root cause: saveJob() used stale sourceDatasourceId (set once on load) instead of live datasourceId (updated by ConfigTabForm via $bindable). Since sourceDatasourceId was always truthy, the || fallback to datasourceId never triggered — the old datasource ID was always sent to PUT. Fixes: - Removed dead sourceDatasourceId atom; saveJob() uses datasourceId directly - Bound sourceTable via $bindable through ConfigTabForm; updated on select - loadDatasourceColumns() syncs databaseDialect from Superset columns API - saveJob() sends undefined for database_dialect="unknown" to force re-detect - Backend: added direct_db+connection_id validation on update (mirroring create) - Removed redundant "Язык ист." column from TranslationPreview table - Removed unused getDetectedLang function Tests: - TranslationJobModel: datasourceId save mapping, dialect sync, unknown→undefined - TranslateJobService: reject direct_db without connection_id, preserve existing Verified: browser — translate_cross datasource persisted after save+reload, dialect detected as "clickhouse", columns loaded (2), translation column preserved.
This commit is contained in:
@@ -324,6 +324,31 @@ class TestUpdateJob:
|
||||
job = await svc.update_job(JOB_ID, payload)
|
||||
assert job.target_languages == ["fr"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_direct_db_without_connection_id_rejected(self, db_session):
|
||||
"""direct_db updates require an effective connection_id."""
|
||||
config = MagicMock()
|
||||
svc = TranslateJobService(db_session, config)
|
||||
payload = TranslateJobUpdate(insert_method="direct_db", connection_id=None)
|
||||
|
||||
with pytest.raises(ValueError, match="connection_id is required"):
|
||||
await svc.update_job(JOB_ID, payload)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_direct_db_preserves_existing_connection_id(self, db_session):
|
||||
"""direct_db update is valid when the existing job already has connection_id."""
|
||||
config = MagicMock()
|
||||
svc = TranslateJobService(db_session, config)
|
||||
base = svc.get_job(JOB_ID)
|
||||
base.connection_id = "conn-1"
|
||||
db_session.commit()
|
||||
|
||||
payload = TranslateJobUpdate(insert_method="direct_db")
|
||||
job = await svc.update_job(JOB_ID, payload)
|
||||
|
||||
assert job.insert_method == "direct_db"
|
||||
assert job.connection_id == "conn-1"
|
||||
|
||||
|
||||
class TestDeleteJob:
|
||||
"""Verify delete_job."""
|
||||
|
||||
Reference in New Issue
Block a user