Skip to content

Add script to rollback failed import#613

Open
vish-cs wants to merge 1 commit into
datacommonsorg:masterfrom
vish-cs:rollback
Open

Add script to rollback failed import#613
vish-cs wants to merge 1 commit into
datacommonsorg:masterfrom
vish-cs:rollback

Conversation

@vish-cs

@vish-cs vish-cs commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new script, retry_failed_ingestion.py, along with its corresponding unit tests, to automate the rollback and retry process for failed Dataflow ingestion jobs. Feedback on the implementation highlights a critical correctness bug where the workflow could be retriggered even if a rollback fails, and a missing pagination implementation when fetching Dataflow job messages. Additionally, it is recommended to use posixpath instead of os.path for GCS path manipulations to avoid platform-specific path separator issues, and to clean up unused imports in the test file.

Comment thread pipeline/scripts/retry_failed_ingestion.py Outdated
Comment thread pipeline/scripts/retry_failed_ingestion.py Outdated
Comment thread pipeline/scripts/retry_failed_ingestion.py Outdated
Comment thread pipeline/scripts/retry_failed_ingestion.py Outdated
Comment thread pipeline/scripts/retry_failed_ingestion.py Outdated
Comment thread pipeline/scripts/retry_failed_ingestion_test.py Outdated
@codacy-production

codacy-production Bot commented Jul 6, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 medium · 26 minor

Alerts:
⚠ 28 issues (≤ 0 issues of at least minor severity)

Results:
28 new issues

Category Results
Documentation 15 minor
CodeStyle 11 minor
Complexity 2 medium

View in Codacy

🟢 Metrics 68 complexity

Metric Results
Complexity 68

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@vish-cs vish-cs force-pushed the rollback branch 2 times, most recently from a3696c4 to 5bb4e0a Compare July 6, 2026 08:47
@vish-cs vish-cs requested a review from gmechali July 6, 2026 08:48
Comment thread pipeline/scripts/retry_failed_ingestion.py Outdated
Comment thread pipeline/scripts/retry_failed_ingestion.py Outdated
Comment thread pipeline/scripts/retry_failed_ingestion.py Outdated
logging.error(f"Error parsing importList parameter: {e}")

logging.info(f"Fetching error messages for Dataflow job {job_id}...")
request = dataflow.projects().locations().jobs().messages().list(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to only be checking dataflow for failures. What if the failures came from elsewhere in the worfklow (spanner embeddings, ingestion helper issue, bq federation).

What's the long term plan for this, should we be checking all the stages? Should the workflow be modified to propoagate errors from dataflow? (if that's even possible)

def _revert_txn(transaction):
# 1. Get current version from ImportStatus to know what to avoid.
status_sql = """
SELECT LatestVersion FROM ImportStatus

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given the changes we discussed to IngestionHistory last week, isnt that a better place to read this from? ImportStatus seems brittle given that if we have started a new workflow since, that information is gone.

"""
status_results = transaction.execute_sql(
status_sql,
params={'importName': short_name},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How would this work for a multi-provenance import?
Like if I import WHO and ILO at once?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The script checks for the dataflow logs to see if it finds a specific failed import and reverts it. Else, it falls back to reverting all the imports in that batch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants