Skip to content

Commit 08db485

Browse files
authored
Merge branch 'development' into jac/1807-document-api-sample
2 parents ad58541 + 7bb9852 commit 08db485

5 files changed

Lines changed: 70 additions & 19 deletions

File tree

‎samples/explore_workbook.py‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ def main():
3030
parser.add_argument(
3131
"--powerpoint", "-ppt", metavar="FILENAME", help="filename (a .ppt file) to save the powerpoint deck"
3232
)
33+
parser.add_argument(
34+
"--delete",
35+
action="store_true",
36+
help="delete the last custom view on the site after the update/export demo",
37+
)
3338

3439
args = parser.parse_args()
3540

@@ -60,6 +65,7 @@ def main():
6065
all_workbooks = list(TSC.Pager(server.workbooks))
6166
print([workbook.name for workbook in all_workbooks])
6267

68+
custom_views = []
6369
if all_workbooks:
6470
# Pick one workbook from the list
6571
sample_workbook = all_workbooks[0]
@@ -117,23 +123,26 @@ def main():
117123

118124
# Get custom views. `.get()` only returns the first page;
119125
# use TSC.Pager to iterate every custom view on the site.
120-
for c in TSC.Pager(server.custom_views):
126+
custom_views = list(TSC.Pager(server.custom_views))
127+
for c in custom_views:
121128
print(c)
122129

123-
# for the last custom view in the list
130+
if custom_views:
131+
# For the last custom view in the list.
132+
c = custom_views[-1]
124133

125-
# update the name
126-
# note that this will fail if the name is already changed to this value
127-
changed: TSC.CustomViewItem(id=c.id, name="I was updated by tsc")
128-
verified_change = server.custom_views.update(changed)
129-
print(verified_change)
134+
# update the name
135+
# note that this will fail if the name is already changed to this value
136+
changed = TSC.CustomViewItem(id=c.id, name="I was updated by tsc")
137+
verified_change = server.custom_views.update(changed)
138+
print(verified_change)
130139

131-
# export as image. Filters etc could be added here as usual
132-
server.custom_views.populate_image(c)
133-
filename = c.id + "-image-export.png"
134-
with open(filename, "wb") as f:
135-
f.write(c.image)
136-
print("saved to " + filename)
140+
# export as image. Filters etc could be added here as usual
141+
server.custom_views.populate_image(c)
142+
filename = c.id + "-image-export.png"
143+
with open(filename, "wb") as f:
144+
f.write(c.image)
145+
print("saved to " + filename)
137146

138147
if args.powerpoint:
139148
# Populate workbook preview image
@@ -143,9 +152,12 @@ def main():
143152
print(f"\nDownloaded powerpoint of workbook to {os.path.abspath(args.powerpoint)}")
144153

145154
if args.delete:
146-
print(f"deleting {c.id}")
147-
unlucky = TSC.CustomViewItem(c.id)
148-
server.custom_views.delete(unlucky.id)
155+
if not custom_views:
156+
print("--delete requested but no custom views on this site; nothing to delete.")
157+
else:
158+
print(f"deleting {c.id}")
159+
unlucky = TSC.CustomViewItem(c.id)
160+
server.custom_views.delete(unlucky.id)
149161

150162

151163
if __name__ == "__main__":

‎samples/list_jobs.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,14 @@ def _wait_for_job(server, job_id, timeout):
131131
raise SystemExit(2)
132132
except JobFailedException as exc:
133133
# The exception carries the failed JobItem so callers can inspect it.
134-
print(f"Job {job_id} failed: notes={exc.job.notes}")
134+
# `notes` is the legacy list[str] surface; `status_notes` is the structured
135+
# list[dict] shape emitted for modern job types (see JobItem docstring).
136+
print(f"Job {job_id} failed: notes={exc.job.notes} status_notes={exc.job.status_notes}")
135137
raise SystemExit(1) from exc
136138

137-
print(f"Job {job_id} finished. finish_code={job.finish_code} notes={job.notes}")
139+
print(
140+
f"Job {job_id} finished. finish_code={job.finish_code}" f" notes={job.notes} status_notes={job.status_notes}"
141+
)
138142

139143

140144
if __name__ == "__main__":

‎tableauserverclient/__init__.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
RequestOptions,
6868
MissingRequiredFieldError,
6969
FailedSignInError,
70+
FlowRunCancelledException,
71+
FlowRunFailedException,
72+
JobCancelledException,
73+
JobFailedException,
7074
NotSignedInError,
7175
ServerResponseError,
7276
Filter,
@@ -98,13 +102,17 @@
98102
"FileuploadItem",
99103
"Filter",
100104
"FlowItem",
105+
"FlowRunCancelledException",
106+
"FlowRunFailedException",
101107
"FlowRunItem",
102108
"get_versions",
103109
"GroupItem",
104110
"GroupSetItem",
105111
"HourlyInterval",
106112
"ImageRequestOptions",
107113
"IntervalItem",
114+
"JobCancelledException",
115+
"JobFailedException",
108116
"JobItem",
109117
"JWTAuth",
110118
"LinkedTaskFlowRunItem",

‎tableauserverclient/server/__init__.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
from tableauserverclient.server.sort import Sort
1313
from tableauserverclient.server.server import Server
1414
from tableauserverclient.server.pager import Pager
15-
from tableauserverclient.server.endpoint.exceptions import FailedSignInError, NotSignedInError
15+
from tableauserverclient.server.endpoint.exceptions import (
16+
FailedSignInError,
17+
FlowRunCancelledException,
18+
FlowRunFailedException,
19+
JobCancelledException,
20+
JobFailedException,
21+
NotSignedInError,
22+
)
1623

1724
from tableauserverclient.server.endpoint import (
1825
Auth,
@@ -60,6 +67,10 @@
6067
"Server",
6168
"Pager",
6269
"FailedSignInError",
70+
"FlowRunCancelledException",
71+
"FlowRunFailedException",
72+
"JobCancelledException",
73+
"JobFailedException",
6374
"NotSignedInError",
6475
"Auth",
6576
"CustomViews",

‎test/test_import_surface.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import tableauserverclient as TSC
2+
from tableauserverclient.server.endpoint import exceptions
3+
4+
5+
def test_job_exceptions_at_top_level():
6+
assert TSC.JobFailedException is exceptions.JobFailedException
7+
assert TSC.JobCancelledException is exceptions.JobCancelledException
8+
assert "JobFailedException" in TSC.__all__
9+
assert "JobCancelledException" in TSC.__all__
10+
11+
12+
def test_flow_run_exceptions_at_top_level():
13+
assert TSC.FlowRunFailedException is exceptions.FlowRunFailedException
14+
assert TSC.FlowRunCancelledException is exceptions.FlowRunCancelledException
15+
assert "FlowRunFailedException" in TSC.__all__
16+
assert "FlowRunCancelledException" in TSC.__all__

0 commit comments

Comments
 (0)