Skip to content

Fix wait_for_job for create_extract job ids (#1093) - #1882

Open
jacalata wants to merge 2 commits into
developmentfrom
jac/1093-create-extract-jobs-note
Open

jacalata wants to merge 2 commits into
developmentfrom
jac/1093-create-extract-jobs-note

Conversation

@jacalata

Copy link
Copy Markdown
Contributor

Closes #1093.

Motivation

server.jobs.wait_for_job(job) crashes on JobItems returned by datasources.create_extract and workbooks.create_extract: the server answers GET /jobs/{id} for those ids with ServerResponseError code 400031: There was a problem querying job '{id}'.. The id IS visible through the paginated /jobs listing endpoint.

Reported in 2022, still reproduces on rel-windows on-prem 3.30 and stage-dataplane1 Cloud 3.30 against the monolith's Batters (TestV1).tdsx today (2026-09-18). Public docs don't mention this quirk.

Behavior change

  • wait_for_job catches the specific 400031 error from get_by_id and falls back to polling the paginated /jobs listing (Pager(server.jobs) with pagesize=1000, matching on id).
  • The BackgroundJobItem the listing returns is translated into a JobItem so the return type stays stable. Fields absent from BackgroundJobItem come back as documented defaults (progress="", notes=[], status_notes=[], plus several Nones — documented in the wait_for_job docstring).
  • Terminal statuses (Success / Failed / Cancelled) map to their JobItem.FinishCode. Anything else — Pending, InProgress, an unknown future status, missing status — keeps completed_at=None so the outer poll loop re-polls, with finish_code=-1 as a sentinel so a reader inspecting finish_code without gating on completed_at can't mistake an unfinished job for Success.
  • Jobs.get_by_id is unchanged. Direct callers still see the raw server error; the fallback only kicks in through wait_for_job.
  • If wait_for_job gets 400031 AND the id isn't in the listing (only fires on a rare create-vs-listing race), the original 400031 is re-raised — no new exception type invented.
  • Any ServerResponseError with a code other than 400031 propagates untouched — no listing fallback.

The create_extract docstrings on datasources_endpoint.py and workbooks_endpoint.py note the quirk and point callers at wait_for_job for transparent handling. wait_for_job's own Notes section describes the fallback + the synthesized-field defaults.

Test plan

  • Six new pytest cases in test/test_job.py:
    • happy path (no listing hit — sanity guard against future regressions)
    • fallback success / failed / cancelled
    • fallback in-progress → success (verifies the outer poll loop iterates through the fallback)
    • fallback walks multiple listing pages
    • fallback timeout (deterministic via mocked_time)
    • fallback where id isn't in the listing (re-raises 400031)
    • non-400031 propagation (no listing fallback fires)
  • Full suite: pytest test/ → 936 passed / 1 skipped.
  • black --check clean; mypy 0 issues across 214 files.
  • Manually verified 400031 reproduces fresh on 2026-09-18 on rel-windows and stage-dataplane1 using the monolith's Batters (TestV1).tdsx.

🤖 Generated with Claude Code

Tableau Server returns a JobItem from create_extract on datasources and
workbooks whose id is not addressable via GET /jobs/{id} -- that call
raises ServerResponseError with code 400031. The id IS visible through
the paginated /jobs listing endpoint.

wait_for_job now catches the 400031 error and transparently falls back
to polling /jobs, matching on id, and translating the resulting
BackgroundJobItem into a JobItem so the return type stays stable.
Callers that use wait_for_job are covered without changing their code.
Direct callers of get_by_id still see the raw server error.

BackgroundJobItem carries fewer fields than JobItem, so the translated
JobItem returns defaults for the missing fields (documented in the
wait_for_job docstring). Success/Failed/Cancelled map to their
FinishCode; anything else keeps completed_at=None so the outer poll
loop re-polls, with finish_code=-1 as a sentinel so a reader inspecting
finish_code alone can't mistake an unfinished job for Success.

Six new pytest cases cover the happy path (no listing hit), fallback
happy/failed/cancelled, in-progress iteration, multi-page pager walk,
timeout in the fallback, non-400031 propagation, and job-not-in-listing
(re-raises 400031).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 18, 2026 20:45

Copilot AI 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.

🟢 Approval recommended

The fallback is narrowly scoped, preserves existing error behavior, and has comprehensive regression coverage.

Pull request overview

Adds a targeted fallback for unqueryable create_extract job IDs while preserving existing get_by_id behavior.

Changes:

  • Polls the paginated jobs listing when GET /jobs/{id} returns error 400031.
  • Translates listing results into stable JobItem instances.
  • Adds regression tests and documents the server quirk.
File summaries
File Description
tableauserverclient/server/endpoint/jobs_endpoint.py Implements fallback polling and JobItem conversion.
tableauserverclient/server/endpoint/datasources_endpoint.py Documents the datasource extract behavior.
tableauserverclient/server/endpoint/workbooks_endpoint.py Documents the workbook extract behavior.
test/test_job.py Adds fallback, pagination, timeout, and error-propagation tests.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…e-extract-jobs-note

# Conflicts:
#	tableauserverclient/server/endpoint/jobs_endpoint.py
Copilot AI lite review requested due to automatic review settings December 3, 2026 02:20
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
tableauserverclient
   __init__.py50100% 
   config.py150100% 
   datetime_helpers.py2511 96%
   exponential_backoff.py200100% 
   filesys_helpers.py310100% 
   namespace.py2533 88%
tableauserverclient/bin
   __init__.py20100% 
   _version.py358212212 41%
tableauserverclient/helpers
   __init__.py10100% 
   logging.py20100% 
   strings.py3111 97%
tableauserverclient/models
   __init__.py470100% 
   auth_federation_item.py8799 90%
   collection_item.py4177 83%
   column_item.py553232 42%
   connection_credentials.py351111 69%
   connection_item.py1131313 88%
   custom_view_item.py1442121 85%
   data_acceleration_report_item.py5411 98%
   data_alert_item.py15844 97%
   data_freshness_policy_item.py1551515 90%
   database_item.py2073636 83%
   datasource_item.py3001212 96%
   dqw_item.py10455 95%
   exceptions.py40100% 
   extensions_item.py13244 97%
   extract_item.py4444 91%
   favorites_item.py6988 88%
   fileupload_item.py190100% 
   flow_item.py1491010 93%
   flow_run_item.py710100% 
   group_item.py8966 93%
   groupset_item.py4977 86%
   interval_item.py1823232 82%
   job_item.py1921010 95%
   linked_tasks_item.py7911 99%
   location_item.py2922 93%
   metric_item.py1291313 90%
   oidc_item.py6333 95%
   pagination_item.py3411 97%
   permissions_item.py1111212 89%
   project_item.py2073131 85%
   property_decorators.py1001818 82%
   reference_item.py2622 92%
   revision_item.py5911 98%
   schedule_item.py20966 97%
   server_info_item.py3777 81%
   site_item.py6361313 98%
   subscription_item.py10111 99%
   table_item.py1191818 85%
   tableau_auth.py612525 59%
   tableau_types.py2711 96%
   tag_item.py150100% 
   target.py60100% 
   task_item.py5922 97%
   user_item.py3381717 95%
   view_item.py2201616 93%
   virtual_connection_item.py6488 88%
   webhook_item.py8533 96%
   workbook_item.py3691616 96%
tableauserverclient/server
   __init__.py90100% 
   exceptions.py40100% 
   filter.py2911 97%
   pager.py3311 97%
   query.py1431313 91%
   request_factory.py1377185185 87%
   request_options.py38655 99%
   server.py2582222 91%
   sort.py60100% 
tableauserverclient/server/endpoint
   __init__.py360100% 
   auth_endpoint.py1141010 91%
   auth_federation_endpoint.py800100% 
   custom_views_endpoint.py1521212 92%
   data_acceleration_report_endpoint.py210100% 
   data_alert_endpoint.py942323 76%
   databases_endpoint.py1112929 74%
   datasources_endpoint.py3233333 90%
   default_permissions_endpoint.py4633 93%
   dqw_endpoint.py451616 64%
   endpoint.py2602222 92%
   exceptions.py7966 92%
   extensions_endpoint.py310100% 
   favorites_endpoint.py942222 77%
   fileuploads_endpoint.py510100% 
   flow_runs_endpoint.py6299 85%
   flow_task_endpoint.py2122 90%
   flows_endpoint.py1984747 76%
   groups_endpoint.py12699 93%
   groupsets_endpoint.py7277 90%
   jobs_endpoint.py9366 94%
   linked_tasks_endpoint.py370100% 
   metadata_endpoint.py881414 84%
   metrics_endpoint.py5566 89%
   oidc_endpoint.py4211 98%
   permissions_endpoint.py4433 93%
   projects_endpoint.py1792424 87%
   resource_tagger.py1273535 72%
   schedules_endpoint.py1531414 91%
   server_info_endpoint.py361010 72%
   sites_endpoint.py1302727 79%
   subscriptions_endpoint.py561414 75%
   tables_endpoint.py1103636 67%
   tasks_endpoint.py6366 90%
   users_endpoint.py17077 96%
   views_endpoint.py17399 95%
   virtual_connections_endpoint.py1131010 91%
   webhooks_endpoint.py5599 84%
   workbooks_endpoint.py3382222 93%
TOTAL12521141189% 

Copilot AI 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.

🟢 Approval recommended

No active review issues remain, and the change is supported by documented handling plus regression coverage for fallback polling, terminal states, pagination, timeouts, and error propagation.

No open issues 🎉

Review effort: Lite

This branch has not been deployed

No deployments
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.

server.jobs.wait_for_job fails for ID generated by create_extract

2 participants